mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-11-11 00:41:45 +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
3 changed files with 30 additions and 4 deletions
|
|
@ -66,12 +66,14 @@ class DatabaseManager
|
||||||
db = @_databases[databasePath]
|
db = @_databases[databasePath]
|
||||||
|
|
||||||
if not db
|
if not db
|
||||||
err = new Error("Database not prepared"); result = null
|
result = null
|
||||||
event.sender.send('database-result', {queryKey, err, result})
|
errJSONString = JSON.stringify(new Error("Database not prepared"))
|
||||||
|
event.sender.send('database-result', {queryKey, errJSONString, result})
|
||||||
return
|
return
|
||||||
|
|
||||||
@_query db, query, values, (err, result) ->
|
@_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
|
# Resolves when a new database has been created and the initial setup
|
||||||
# migration has run successfuly.
|
# migration has run successfuly.
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,21 @@ if (process.type === 'renderer') {
|
||||||
}
|
}
|
||||||
var logpath = path.join(tmpPath, 'edgehill-' + logpid + '.log');
|
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() {
|
module.exports = ErrorReporter = (function() {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -79,12 +79,21 @@ class DatabaseConnection
|
||||||
databasePath = @_databasePath
|
databasePath = @_databasePath
|
||||||
ipc.send('database-query', {databasePath, queryKey, query, values})
|
ipc.send('database-query', {databasePath, queryKey, query, values})
|
||||||
|
|
||||||
_onDatabaseResult: ({queryKey, err, result}) =>
|
_onDatabaseResult: ({queryKey, errJSONString, result}) =>
|
||||||
record = @_queryRecords[queryKey]
|
record = @_queryRecords[queryKey]
|
||||||
return unless record
|
return unless record
|
||||||
|
|
||||||
{query, start, values, reject, resolve, options} = 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)
|
@_logQuery(query, start, result)
|
||||||
|
|
||||||
if options.evaluateImmediately
|
if options.evaluateImmediately
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue