def DealWithBrokenJSONDump(db_dir, dump, dump_descriptor):

    timestamp_string = time.strftime('%Y-%m-%d %H-%M-%S')
    hex_chars = os.urandom(4).hex()

    filename = '({}) at {} {}.json'.format(dump_descriptor, timestamp_string,
                                           hex_chars)

    path = os.path.join(db_dir, filename)

    with open(path, 'wb') as f:

        if isinstance(dump, str):

            dump = bytes(dump, 'utf-8', errors='replace')

        f.write(dump)

    message = 'A serialised object failed to load! Its description is "{}".'.format(
        dump_descriptor)
    message += os.linesep * 2
    message += 'This error could be due to several factors, but is most likely a hard drive fault (perhaps your computer recently had a bad power cut?).'
    message += os.linesep * 2
    message += 'The database has attempted to delete the broken object, and the object\'s dump written to {}. Depending on the object, your client may no longer be able to boot, or it may have lost something like a session or a subscription.'.format(
        path)
    message += os.linesep * 2
    message += 'Please review the \'help my db is broke.txt\' file in your install_dir/db directory as background reading, and if the situation or fix here is not obvious, please contact hydrus dev.'

    HydrusData.ShowText(message)

    raise HydrusExceptions.SerialisationException(message)
Beispiel #2
0
 def InitialiseFromSerialisableInfo( self, version, serialisable_info, raise_error_on_future_version = False ):
     
     if version > self.SERIALISABLE_VERSION:
         
         if raise_error_on_future_version:
             
             message = 'Unfortunately, an object of type {} could not be loaded because it was created in a client that uses an updated version of that object! This client supports versions up to {}, but the object was version {}.'.format( self.SERIALISABLE_NAME, self.SERIALISABLE_VERSION, version )
             message += os.linesep * 2
             message += 'Please update your client to import this object.'
             
             raise HydrusExceptions.SerialisationException( message )
             
         else:
             
             message = 'An object of type {} was created in a client that uses an updated version of that object! This client supports versions up to {}, but the object was version {}. For now, the client will try to continue work, but things may break. If you know why this has occured, please correct it. If you do not, please let hydrus dev know.'.format( self.SERIALISABLE_NAME, self.SERIALISABLE_VERSION, version )
             
             HydrusData.ShowText( message )
             
         
     
     while version < self.SERIALISABLE_VERSION:
         
         ( version, serialisable_info ) = self._UpdateSerialisableInfo( version, serialisable_info )
         
     
     self._InitialiseFromSerialisableInfo( serialisable_info )