TryGhost / Ghost

Independent technology for modern publishing, memberships, subscriptions and newsletters.
https://ghost.org
MIT License
47.04k stars 10.24k forks source link

Bug: error without message could make a new error #4381

Closed meowtec closed 9 years ago

meowtec commented 9 years ago

file: core/server/errors/index.js Line: 110

err = _.isString(err) ? err : (_.isObject(err) ? err.message : 'An unknown error occurred.');
if (err.indexOf('SQLITE_READONLY') !== -1) {

If err is like this:

{
code: 401, error: 'expired token' 
}

then an new error ERROR: Cannot call method 'indexOf' of undefined will be thrown.

novaugust commented 9 years ago

Hi @meowtec, welcome to Ghost =) I'm not sure if you're reporting a bug you've run into, or if you're just commenting on the code. If it's the former, could you give us some more specifics per the bug reporting guidelines? And if it's the latter, the line above the indexOf check makes sure that err is a string (unless err.message isn't a string, I suppose...), and so indexOf is defined.

novaugust commented 9 years ago

I'm just going to close this for now to keep things cleaned up, I'll be happy to reopen it if you can provide the bug report details

meowtec commented 9 years ago

Hi @novaugust, I am using a ghost copy forked from TryGhost/Ghost. In this copy, the mender replace the local file storage to a cloud storage called qiniu. And he use a SDK provided by qiniu cloud storage, The SDK will throw an error if something wrong happen. On the error object, property message is undefined. so ERROR: Cannot call method 'indexOf' of undefined happend..

I am not good at English, so I wish you will understande what I mean.

if another module which Ghost dependences throw an err (isObject) without message property,here will be a new error ERROR: Cannot call method 'indexOf' of undefined.

jaswilli commented 9 years ago

Hi @meowtec ,

I see the problem that you're talking about and there is definitely a case in which an error could be produced. If you're interested in fixing it we'd happily take a pull request on it, otherwise I can just re-open this issue so we're aware of it and it'll get fixed down the road.