mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-09-22 00:06:06 +08:00
fix(database): Ensure errors reach the renderer-side by sending them as JSON strings, reinflating as Errors
This commit is contained in:
parent
c3a90e4f5d
commit
ef960b21c8
|
@ -66,12 +66,14 @@ class DatabaseManager
|
|||
db = @_databases[databasePath]
|
||||
|
||||
if not db
|
||||
err = new Error("Database not prepared"); result = null
|
||||
event.sender.send('database-result', {queryKey, err, result})
|
||||
result = null
|
||||
errJSONString = JSON.stringify(new Error("Database not prepared"))
|
||||
event.sender.send('database-result', {queryKey, errJSONString, result})
|
||||
return
|
||||
|
||||
@_query db, query, values, (err, result) ->
|
||||
event.sender.send('database-result', {queryKey, err, result})
|
||||
errJSONString = JSON.stringify(err)
|
||||
event.sender.send('database-result', {queryKey, errJSONString, result})
|
||||
|
||||
# Resolves when a new database has been created and the initial setup
|
||||
# migration has run successfuly.
|
||||
|
|
|
@ -22,6 +22,21 @@ if (process.type === 'renderer') {
|
|||
}
|
||||
var logpath = path.join(tmpPath, 'edgehill-' + logpid + '.log');
|
||||
|
||||
// globally define Error.toJSON. This allows us to pass errors via IPC
|
||||
// and through the Action Bridge. Note:they are not re-inflated into
|
||||
// Error objects automatically.
|
||||
Object.defineProperty(Error.prototype, 'toJSON', {
|
||||
value: function () {
|
||||
var alt = {};
|
||||
|
||||
Object.getOwnPropertyNames(this).forEach(function (key) {
|
||||
alt[key] = this[key];
|
||||
}, this);
|
||||
|
||||
return alt;
|
||||
},
|
||||
configurable: true
|
||||
});
|
||||
|
||||
module.exports = ErrorReporter = (function() {
|
||||
|
||||
|
|
|
@ -79,12 +79,21 @@ class DatabaseConnection
|
|||
databasePath = @_databasePath
|
||||
ipc.send('database-query', {databasePath, queryKey, query, values})
|
||||
|
||||
_onDatabaseResult: ({queryKey, err, result}) =>
|
||||
_onDatabaseResult: ({queryKey, errJSONString, result}) =>
|
||||
record = @_queryRecords[queryKey]
|
||||
return unless record
|
||||
|
||||
{query, start, values, reject, resolve, options} = record
|
||||
|
||||
if errJSONString
|
||||
# Note: Error objects turn into JSON when went through the IPC bridge.
|
||||
# In case downstream code checks instanceof Error, convert back into
|
||||
# a real error objet.
|
||||
errJSON = JSON.parse(errJSONString)
|
||||
err = new Error()
|
||||
for key, val of errJSON
|
||||
err[key] = val
|
||||
|
||||
@_logQuery(query, start, result)
|
||||
|
||||
if options.evaluateImmediately
|
||||
|
|
Loading…
Reference in a new issue