Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnicodeEncodeError when attempting to sync paths that contain surrogates escapes #230

Closed
adrienlourdin opened this issue Nov 19, 2020 · 26 comments · Fixed by #238
Closed
Labels
bug Something isn't working daemon

Comments

@adrienlourdin
Copy link

Daemon os starting but stops syncing due to unexpected error:

Traceback (most recent call last):
File "/home/adrien/.local/lib/python3.8/site-packages/maestral/sync.py", line 3864, in startup_worker
sync.upload_local_changes_while_inactive()
File "/home/adrien/.local/lib/python3.8/site-packages/maestral/sync.py", line 1782, in upload_local_changes_while_inactive
events, local_cursor = self._get_local_changes_while_inactive()

File "/home/adrien/.local/lib/python3.8/site-packages/maestral/sync.py", line 1819, in _get_local_changes_while_inactive
ctime_check = now > stats.st_ctime > self.get_last_sync(dbx_path_lower)
File "/home/adrien/.local/lib/python3.8/site-packages/maestral/sync.py", line 1102, in get_last_sync
res = self._db_session.query(IndexEntry).get(dbx_path.lower())
File "/usr/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 1018, in get
return self._get_impl(ident, loading.load_on_pk_identity)
File "/usr/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 1135, in _get_impl
return db_load_fn(self, primary_key_identity)
File "/usr/lib/python3.8/site-packages/sqlalchemy/orm/loading.py", line 286, in load_on_pk_identity
return q.one()
File "/usr/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 3490, in one
ret = self.one_or_none()
File "/usr/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 3459, in one_or_none
ret = list(self)
File "/usr/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 3535, in iter
return self._execute_and_instances(context)
File "/usr/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 3560, in _execute_and_instances
result = conn.execute(querycontext.statement, self._params)
File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1011, in execute
return meth(self, multiparams, params)
File "/usr/lib/python3.8/site-packages/sqlalchemy/sql/elements.py", line 298, in _execute_on_connection
return connection._execute_clauseelement(self, multiparams, params)
File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1124, in _execute_clauseelement
ret = self._execute_context(
File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1316, in _execute_context
self.handle_dbapi_exception(
File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1514, in handle_dbapi_exception
util.raise
(exc_info[1], with_traceback=exc_info[2])
File "/usr/lib/python3.8/site-packages/sqlalchemy/util/compat.py", line 182, in raise

raise exception
File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1276, in _execute_context
self.dialect.do_execute(
File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 593, in do_execute
cursor.execute(statement, parameters)
UnicodeEncodeError: 'utf-8' codec can't encode character '\udce4' in position 192: surrogates not allowed

@samschott
Copy link
Owner

Uh, that looks like a non-utf-8 character in a file name. Which encoding is your file system system using? You can find out in Python with:

import sys
sys.getfilesystemencoding()

@samschott
Copy link
Owner

This error seems to happen because Python cannot decode the bytes provided for a file path. From their documentation:

On some systems, conversion using the file system encoding may fail. In this case, Python uses the surrogateescape encoding error handler, which means that undecodable bytes are replaced by a Unicode character U+DCxx on decoding, and these are again translated to the original byte on encoding.

Unfortunately, sqlite3 does not like surrogate escapes.

@adrienlourdin
Copy link
Author

adrienlourdin commented Nov 19, 2020 via email

@samschott
Copy link
Owner

f2fs is the file system, however the issue seems to be a non-unicode character in one of the filenames.

It would be easiest if you find the offending file and rename it. If you set the log level to debug with maestral log level DEBUG and try syncing again, the log will show which file it last attempted to sync before the error. You can show the logs with maestral log show -e.

When you are sure that the problematic file name is gone but the error persists, a brute-force method would be to rebuild the index. You can stop the daemon first and then schedule a rebuild for the next startup with maestral rebuild-index.

While such filenames will almost certainly be also rejected by Dropbox servers it would still be nice to handle those errors more gracefully. I'll see what I can do for the next release.

@samschott samschott changed the title Maestral unexpected error Unhandled UnicodeEncodeError when querying the database with paths that contain surrogates escapes Nov 19, 2020
@samschott samschott changed the title Unhandled UnicodeEncodeError when querying the database with paths that contain surrogates escapes UnicodeEncodeError when attempting to sync paths that contain surrogates escapes Nov 19, 2020
@adrienlourdin
Copy link
Author

adrienlourdin commented Nov 19, 2020 via email

@adrienlourdin
Copy link
Author

adrienlourdin commented Nov 20, 2020

Log result

2020-11-18 23:34:07 maestral.sync INFO: Creating folders...
2020-11-18 23:34:07 maestral.sync INFO: Creating folder 1/5...
2020-11-18 23:34:09 maestral.sync INFO: Downloading 127/495...
2020-11-18 23:34:11 maestral.sync INFO: Downloading 266/495...
2020-11-18 23:34:13 maestral.sync INFO: Downloading 406/495...
2020-11-18 23:34:14 maestral.client INFO: Indexing 6501...
2020-11-18 23:34:17 maestral.sync INFO: Creating folders...
2020-11-18 23:34:17 maestral.sync INFO: Creating folder 1/4...
2020-11-18 23:34:19 maestral.sync INFO: Downloading 118/494...
2020-11-18 23:34:21 maestral.sync INFO: Downloading 255/494...
2020-11-18 23:34:23 maestral.sync INFO: Downloading 391/494...
2020-11-18 23:34:25 maestral.client INFO: Indexing 7001...
2020-11-18 23:34:27 maestral.sync INFO: Creating folders...
2020-11-18 23:34:27 maestral.sync INFO: Creating folder 1/3...
2020-11-18 23:34:29 maestral.sync INFO: Downloading 129/497...
2020-11-18 23:34:31 maestral.sync INFO: Downloading 258/497...
2020-11-18 23:34:33 maestral.sync INFO: Downloading 386/497...
2020-11-18 23:34:35 maestral.client INFO: Indexing 7501...
2020-11-18 23:34:37 maestral.sync INFO: Creating folders...
2020-11-18 23:34:37 maestral.sync INFO: Creating folder 1/2...
2020-11-18 23:34:39 maestral.sync INFO: Downloading 118/498...
2020-11-18 23:34:41 maestral.sync INFO: Downloading 246/498...
2020-11-18 23:34:43 maestral.sync INFO: Downloading 373/498...
2020-11-18 23:34:45 maestral.client INFO: Indexing 8001...
2020-11-18 23:34:46 maestral.sync INFO: Creating folders...
2020-11-18 23:34:46 maestral.sync INFO: Creating folder 1/2...
2020-11-18 23:34:48 maestral.sync INFO: Downloading 73/383...
2020-11-18 23:34:50 maestral.sync INFO: Downloading 193/383...
2020-11-18 23:34:52 maestral.sync INFO: Downloading 319/383...
2020-11-18 23:34:54 maestral.client INFO: Indexing 8420...
2020-11-18 23:34:55 maestral.sync INFO: Creating folders...
2020-11-18 23:34:55 maestral.sync INFO: Creating folder 1/1...
2020-11-18 23:34:57 maestral.sync INFO: Downloading 92/244...
2020-11-18 23:34:59 maestral.sync INFO: Downloading 230/244...
2020-11-18 23:35:00 maestral.client INFO: Indexing 8701...
2020-11-18 23:35:01 maestral.sync INFO: Creating folders...
2020-11-18 23:35:01 maestral.sync INFO: Creating folder 1/52...
2020-11-18 23:35:03 maestral.sync INFO: Downloading 80/342...
2020-11-18 23:35:05 maestral.sync INFO: Downloading 197/342...
2020-11-18 23:35:07 maestral.sync INFO: Downloading 325/342...
2020-11-18 23:35:09 maestral.client INFO: Indexing 9095...
2020-11-18 23:35:10 maestral.sync INFO: Creating folders...
2020-11-18 23:35:10 maestral.sync INFO: Creating folder 1/34...
2020-11-18 23:35:12 maestral.sync INFO: Downloading 102/207...
2020-11-18 23:35:14 maestral.client INFO: Indexing 9336...
2020-11-18 23:35:15 maestral.sync INFO: Creating folders...
2020-11-18 23:35:15 maestral.sync INFO: Creating folder 1/28...
2020-11-18 23:35:17 maestral.sync INFO: Downloading 96/178...
2020-11-18 23:35:19 maestral.client INFO: Indexing 9542...
2020-11-18 23:35:19 maestral.sync INFO: Creating folders...
2020-11-18 23:35:20 maestral.sync INFO: Creating folder 1/12...
2020-11-18 23:35:22 maestral.sync INFO: Downloading 106/115...
2020-11-18 23:35:24 maestral.client INFO: Indexing 9669...
2020-11-18 23:35:25 maestral.sync INFO: Creating folders...
2020-11-18 23:35:25 maestral.sync INFO: Creating folder 1/37...
2020-11-18 23:35:27 maestral.sync INFO: Downloading 98/267...
2020-11-18 23:35:29 maestral.sync INFO: Downloading 215/267...
2020-11-18 23:35:30 maestral.client INFO: Indexing 9973...
2020-11-18 23:35:31 maestral.sync INFO: Creating folders...
2020-11-18 23:35:31 maestral.sync INFO: Creating folder 1/53...
2020-11-18 23:35:33 maestral.sync INFO: Downloading 83/301...
2020-11-18 23:35:35 maestral.sync INFO: Downloading 199/301...
2020-11-18 23:35:37 maestral.client INFO: Indexing 10327...
2020-11-18 23:35:38 maestral.sync INFO: Creating folders...
2020-11-18 23:35:38 maestral.sync INFO: Creating folder 1/1...
2020-11-18 23:35:40 maestral.sync INFO: Downloading 95/202...
2020-11-18 23:35:42 maestral.sync INFO: Downloading 201/202...
2020-11-18 23:35:43 maestral.client INFO: Indexing 10555...
2020-11-18 23:35:44 maestral.sync INFO: Creating folders...
2020-11-18 23:35:44 maestral.sync INFO: Creating folder 2/49...
2020-11-18 23:35:46 maestral.sync INFO: Downloading 86/298...
2020-11-18 23:35:48 maestral.sync INFO: Downloading 211/298...
2020-11-18 23:35:50 maestral.sync INFO: Downloading 295/298...
2020-11-18 23:35:51 maestral.client INFO: Indexing 10902...
2020-11-18 23:35:52 maestral.sync INFO: Creating folders...
2020-11-18 23:35:52 maestral.sync INFO: Creating folder 1/3...
2020-11-18 23:35:54 maestral.sync INFO: Downloading 79/346...
2020-11-18 23:35:56 maestral.sync INFO: Downloading 168/346...
2020-11-18 23:35:58 maestral.sync INFO: Downloading 239/346...
2020-11-18 23:36:00 maestral.client INFO: Indexing 11295...
2020-11-18 23:36:01 maestral.sync INFO: Creating folders...
2020-11-18 23:36:01 maestral.sync INFO: Creating folder 1/6...
2020-11-18 23:36:03 maestral.sync INFO: Downloading 48/48...
2020-11-18 23:36:04 maestral.client INFO: Up to date
2020-11-18 23:36:04 maestral.sync INFO: Indexing local changes...
2020-11-18 23:36:08 maestral.sync ERROR: Unexpected error
Traceback (most recent call last):
File "/home/adrien/.local/lib/python3.8/site-packages/maestral/sync.py", line 3864, in startup_worker
sync.upload_local_changes_while_inactive()
File "/home/adrien/.local/lib/python3.8/site-packages/maestral/sync.py", line 1782, in upload_local_changes_while_inactive
events, local_cursor = self._get_local_changes_while_inactive()
File "/home/adrien/.local/lib/python3.8/site-packages/maestral/sync.py", line 1819, in _get_local_changes_while_inactive
ctime_check = now > stats.st_ctime > self.get_last_sync(dbx_path_lower)
File "/home/adrien/.local/lib/python3.8/site-packages/maestral/sync.py", line 1102, in get_last_sync
res = self._db_session.query(IndexEntry).get(dbx_path.lower())
File "/usr/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 1018, in get
return self._get_impl(ident, loading.load_on_pk_identity)
File "/usr/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 1135, in _get_impl
return db_load_fn(self, primary_key_identity)
File "/usr/lib/python3.8/site-packages/sqlalchemy/orm/loading.py", line 286, in load_on_pk_identity
return q.one()
File "/usr/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 3490, in one
ret = self.one_or_none()
File "/usr/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 3459, in one_or_none
ret = list(self)
File "/usr/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 3535, in iter
return self._execute_and_instances(context)
File "/usr/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 3560, in _execute_and_instances
result = conn.execute(querycontext.statement, self._params)
File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1011, in execute
return meth(self, multiparams, params)
File "/usr/lib/python3.8/site-packages/sqlalchemy/sql/elements.py", line 298, in _execute_on_connection
return connection._execute_clauseelement(self, multiparams, params)
File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1124, in _execute_clauseelement
ret = self._execute_context(
File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1316, in _execute_context
self.handle_dbapi_exception(
File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1514, in handle_dbapi_exception
util.raise
(exc_info[1], with_traceback=exc_info[2])
File "/usr/lib/python3.8/site-packages/sqlalchemy/util/compat.py", line 182, in raise

raise exception
File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1276, in _execute_context
self.dialect.do_execute(
File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 593, in do_execute
cursor.execute(statement, parameters)
UnicodeEncodeError: 'utf-8' codec can't encode character '\udce4' in position 195: surrogates not allowed
2020-11-19 07:51:04 maestral.sync INFO: Indexing local changes...
2020-11-19 07:51:09 maestral.sync ERROR: Unexpected error
Traceback (most recent call last):
File "/home/adrien/.local/lib/python3.8/site-packages/maestral/sync.py", line 3864, in startup_worker
sync.upload_local_changes_while_inactive()
File "/home/adrien/.local/lib/python3.8/site-packages/maestral/sync.py", line 1782, in upload_local_changes_while_inactive
events, local_cursor = self._get_local_changes_while_inactive()
File "/home/adrien/.local/lib/python3.8/site-packages/maestral/sync.py", line 1819, in _get_local_changes_while_inactive
ctime_check = now > stats.st_ctime > self.get_last_sync(dbx_path_lower)
File "/home/adrien/.local/lib/python3.8/site-packages/maestral/sync.py", line 1102, in get_last_sync
res = self._db_session.query(IndexEntry).get(dbx_path.lower())
File "/usr/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 1018, in get
return self._get_impl(ident, loading.load_on_pk_identity)
File "/usr/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 1135, in _get_impl
return db_load_fn(self, primary_key_identity)
File "/usr/lib/python3.8/site-packages/sqlalchemy/orm/loading.py", line 286, in load_on_pk_identity
return q.one()
File "/usr/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 3490, in one
ret = self.one_or_none()
File "/usr/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 3459, in one_or_none
ret = list(self)
File "/usr/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 3535, in iter
return self._execute_and_instances(context)
File "/usr/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 3560, in _execute_and_instances
result = conn.execute(querycontext.statement, self._params)
File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1011, in execute
return meth(self, multiparams, params)
File "/usr/lib/python3.8/site-packages/sqlalchemy/sql/elements.py", line 298, in _execute_on_connection
return connection._execute_clauseelement(self, multiparams, params)
File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1124, in _execute_clauseelement
ret = self._execute_context(
File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1316, in _execute_context
self.handle_dbapi_exception(
File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1514, in handle_dbapi_exception
util.raise
(exc_info[1], with_traceback=exc_info[2])
File "/usr/lib/python3.8/site-packages/sqlalchemy/util/compat.py", line 182, in raise

raise exception
File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1276, in _execute_context
self.dialect.do_execute(
File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 593, in do_execute
cursor.execute(statement, parameters)
UnicodeEncodeError: 'utf-8' codec can't encode character '\udce4' in position 192: surrogates not allowed
2020-11-19 23:40:48 maestral.sync INFO: Indexing local changes...
2020-11-19 23:40:54 maestral.sync ERROR: Unexpected error
Traceback (most recent call last):
File "/home/adrien/.local/lib/python3.8/site-packages/maestral/sync.py", line 3864, in startup_worker
sync.upload_local_changes_while_inactive()
File "/home/adrien/.local/lib/python3.8/site-packages/maestral/sync.py", line 1782, in upload_local_changes_while_inactive
events, local_cursor = self._get_local_changes_while_inactive()
File "/home/adrien/.local/lib/python3.8/site-packages/maestral/sync.py", line 1819, in _get_local_changes_while_inactive
ctime_check = now > stats.st_ctime > self.get_last_sync(dbx_path_lower)
File "/home/adrien/.local/lib/python3.8/site-packages/maestral/sync.py", line 1102, in get_last_sync
res = self._db_session.query(IndexEntry).get(dbx_path.lower())
File "/usr/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 1018, in get
return self._get_impl(ident, loading.load_on_pk_identity)
File "/usr/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 1135, in _get_impl
return db_load_fn(self, primary_key_identity)
File "/usr/lib/python3.8/site-packages/sqlalchemy/orm/loading.py", line 286, in load_on_pk_identity
return q.one()
File "/usr/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 3490, in one
ret = self.one_or_none()
File "/usr/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 3459, in one_or_none
ret = list(self)
File "/usr/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 3535, in iter
return self._execute_and_instances(context)
File "/usr/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 3560, in _execute_and_instances
result = conn.execute(querycontext.statement, self._params)
File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1011, in execute
return meth(self, multiparams, params)
File "/usr/lib/python3.8/site-packages/sqlalchemy/sql/elements.py", line 298, in _execute_on_connection
return connection._execute_clauseelement(self, multiparams, params)
File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1124, in _execute_clauseelement
ret = self._execute_context(
File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1316, in _execute_context
self.handle_dbapi_exception(
File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1514, in handle_dbapi_exception
util.raise
(exc_info[1], with_traceback=exc_info[2])
File "/usr/lib/python3.8/site-packages/sqlalchemy/util/compat.py", line 182, in raise

raise exception
File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1276, in _execute_context
self.dialect.do_execute(
File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 593, in do_execute
cursor.execute(statement, parameters)
UnicodeEncodeError: 'utf-8' codec can't encode character '\udce4' in position 195: surrogates not allowed
2020-11-20 14:59:17 maestral.sync DEBUG: Could not load mignore rules from /home/adrien/Dropbox/.mignore: [Errno 2] No such file or directory: '/home/adrien/Dropbox/.mignore'
2020-11-20 14:59:17 maestral.daemon DEBUG: Starting event loop
2020-11-20 14:59:17 maestral.oauth DEBUG: Using keyring: keyring.backends.SecretService.Keyring (priority: 5)
2020-11-20 14:59:19 maestral.sync INFO: Indexing local changes...
2020-11-20 14:59:29 maestral.sync ERROR: Unexpected error
Traceback (most recent call last):
File "/home/adrien/.local/lib/python3.8/site-packages/maestral/sync.py", line 3864, in startup_worker
sync.upload_local_changes_while_inactive()
File "/home/adrien/.local/lib/python3.8/site-packages/maestral/sync.py", line 1782, in upload_local_changes_while_inactive
events, local_cursor = self._get_local_changes_while_inactive()
File "/home/adrien/.local/lib/python3.8/site-packages/maestral/sync.py", line 1819, in _get_local_changes_while_inactive
ctime_check = now > stats.st_ctime > self.get_last_sync(dbx_path_lower)
File "/home/adrien/.local/lib/python3.8/site-packages/maestral/sync.py", line 1102, in get_last_sync
res = self._db_session.query(IndexEntry).get(dbx_path.lower())
File "/usr/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 1018, in get
return self._get_impl(ident, loading.load_on_pk_identity)
File "/usr/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 1135, in _get_impl
return db_load_fn(self, primary_key_identity)
File "/usr/lib/python3.8/site-packages/sqlalchemy/orm/loading.py", line 286, in load_on_pk_identity
return q.one()
File "/usr/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 3490, in one
ret = self.one_or_none()
File "/usr/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 3459, in one_or_none
ret = list(self)
File "/usr/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 3535, in iter
return self._execute_and_instances(context)
File "/usr/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 3560, in _execute_and_instances
result = conn.execute(querycontext.statement, self._params)
File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1011, in execute
return meth(self, multiparams, params)
File "/usr/lib/python3.8/site-packages/sqlalchemy/sql/elements.py", line 298, in _execute_on_connection
return connection._execute_clauseelement(self, multiparams, params)
File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1124, in _execute_clauseelement
ret = self._execute_context(
File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1316, in _execute_context
self.handle_dbapi_exception(
File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1514, in handle_dbapi_exception
util.raise
(exc_info[1], with_traceback=exc_info[2])
File "/usr/lib/python3.8/site-packages/sqlalchemy/util/compat.py", line 182, in raise

raise exception
File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1276, in _execute_context
self.dialect.do_execute(
File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 593, in do_execute
cursor.execute(statement, parameters)
UnicodeEncodeError: 'utf-8' codec can't encode character '\udce4' in position 195: surrogates not allowed
2020-11-20 15:04:00 maestral.sync DEBUG: Could not load mignore rules from /home/adrien/Dropbox/.mignore: [Errno 2] No such file or directory: '/home/adrien/Dropbox/.mignore'
2020-11-20 15:04:05 maestral.sync DEBUG: Could not load mignore rules from /home/adrien/Dropbox/.mignore: [Errno 2] No such file or directory: '/home/adrien/Dropbox/.mignore'
2020-11-20 15:04:05 maestral.oauth DEBUG: Using keyring: keyring.backends.SecretService.Keyring (priority: 5)
2020-11-20 15:04:08 maestral.sync DEBUG: Could not load mignore rules from /home/adrien/Dropbox/.mignore: [Errno 2] No such file or directory: '/home/adrien/Dropbox/.mignore'
2020-11-20 15:04:08 maestral.daemon DEBUG: Starting sync
2020-11-20 15:04:08 maestral.oauth DEBUG: Using keyring: keyring.backends.SecretService.Keyring (priority: 5)
2020-11-20 15:04:10 maestral.sync INFO: Indexing local changes...
2020-11-20 15:04:10 maestral.daemon DEBUG: Starting event loop
2020-11-20 15:04:21 maestral.sync ERROR: Unexpected error
Traceback (most recent call last):
File "/home/adrien/.local/lib/python3.8/site-packages/maestral/sync.py", line 3864, in startup_worker
sync.upload_local_changes_while_inactive()
File "/home/adrien/.local/lib/python3.8/site-packages/maestral/sync.py", line 1782, in upload_local_changes_while_inactive
events, local_cursor = self._get_local_changes_while_inactive()
File "/home/adrien/.local/lib/python3.8/site-packages/maestral/sync.py", line 1819, in _get_local_changes_while_inactive
ctime_check = now > stats.st_ctime > self.get_last_sync(dbx_path_lower)
File "/home/adrien/.local/lib/python3.8/site-packages/maestral/sync.py", line 1102, in get_last_sync
res = self._db_session.query(IndexEntry).get(dbx_path.lower())
File "/usr/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 1018, in get
return self._get_impl(ident, loading.load_on_pk_identity)
File "/usr/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 1135, in _get_impl
return db_load_fn(self, primary_key_identity)
File "/usr/lib/python3.8/site-packages/sqlalchemy/orm/loading.py", line 286, in load_on_pk_identity
return q.one()
File "/usr/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 3490, in one
ret = self.one_or_none()
File "/usr/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 3459, in one_or_none
ret = list(self)
File "/usr/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 3535, in iter
return self._execute_and_instances(context)
File "/usr/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 3560, in _execute_and_instances
result = conn.execute(querycontext.statement, self._params)
File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1011, in execute
return meth(self, multiparams, params)
File "/usr/lib/python3.8/site-packages/sqlalchemy/sql/elements.py", line 298, in _execute_on_connection
return connection._execute_clauseelement(self, multiparams, params)
File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1124, in _execute_clauseelement
ret = self._execute_context(
File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1316, in _execute_context
self.handle_dbapi_exception(
File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1514, in handle_dbapi_exception
util.raise
(exc_info[1], with_traceback=exc_info[2])
File "/usr/lib/python3.8/site-packages/sqlalchemy/util/compat.py", line 182, in raise

raise exception
File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1276, in _execute_context
self.dialect.do_execute(
File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 593, in do_execute
cursor.execute(statement, parameters)
UnicodeEncodeError: 'utf-8' codec can't encode character '\udce4' in position 193: surrogates not allowed

Don t know which file is making trouble.... and i set to maestral log level DEBUG
rebuild index does not work yet as this problematic file is still in my database..

@samschott
Copy link
Owner

Hrm, ok, this is more difficult than I thought. How comfortable are you with Python? Could you run the following code snippet and let me know what it prints?

from maestral.main import Maestral
from maestral.sync import DirectorySnapshot

m = Maestral()
snapshot = DirectorySnapshot(m.dropbox_path)

for path in snapshot.paths:
    try:
        path.encode()
    except UnicodeEncodeError:
        print(path)

@adrienlourdin
Copy link
Author

adrienlourdin commented Nov 20, 2020 via email

@samschott
Copy link
Owner

Sure. It will be easiest if you create a file test.py with the above content. You can then run it the terminal with:

$ python3 test.py

Any file paths that are printed to the terminal are problematic.

@adrienlourdin
Copy link
Author

adrienlourdin commented Nov 20, 2020 via email

@adrienlourdin
Copy link
Author

adrienlourdin commented Nov 20, 2020 via email

@samschott
Copy link
Owner

samschott commented Nov 20, 2020

Of course 🤦‍♂️ A path with cannot be encoded cannot be printed to the terminal.

Could you try again with the modifications below?

from maestral.main import Maestral
from maestral.sync import DirectorySnapshot

m = Maestral()
snapshot = DirectorySnapshot(m.dropbox_path)

for path in snapshot.paths:
    try:
        path.encode()
    except UnicodeEncodeError:
        encoded_path = path.encode("utf-8", "surrogateescape")
        print(encoded_path)

@adrienlourdin
Copy link
Author

adrienlourdin commented Nov 20, 2020 via email

@samschott
Copy link
Owner

Are you sure you copied exactly the Python code which I posted? It looks like there are two print statements in your file...

Sorry to bother you with this :-)

No worries, this error should have been handled better in the first place. As the user base grows, I encounter more niche cases.

@adrienlourdin
Copy link
Author

adrienlourdin commented Nov 20, 2020 via email

@samschott
Copy link
Owner

Github does not allow email attachments, unfortunately. Could you post here instead?

@adrienlourdin
Copy link
Author

adrienlourdin commented Nov 20, 2020 via email

@samschott
Copy link
Owner

Ah, ok. You'll need to copy-paste exactly what I posted, including all of the spaces. This is the file which I have used:

test.py.zip

And it runs without syntax errors.

@adrienlourdin
Copy link
Author

adrienlourdin commented Nov 20, 2020 via email

@samschott
Copy link
Owner

Excellent, glad to hear. I'll work on handling such errors more gracefully than a hard crash.

@adrienlourdin
Copy link
Author

adrienlourdin commented Nov 21, 2020 via email

@samschott
Copy link
Owner

samschott commented Nov 21, 2020 via email

@adrienlourdin
Copy link
Author

adrienlourdin commented Nov 21, 2020 via email

@adrienlourdin
Copy link
Author

adrienlourdin commented Nov 21, 2020 via email

@adrienlourdin
Copy link
Author

adrienlourdin commented Nov 23, 2020 via email

@samschott
Copy link
Owner

Yeah, the issue was a lot more difficult to fix than I had thought. But it should be good now. It'll be rolled out in the next release...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working daemon
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants