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

Exception throw on undefined object key makes it difficult to track down issue #740

Closed
kpdecker opened this issue Oct 13, 2015 · 5 comments
Assignees
Labels
feature New functionality or improvement
Milestone

Comments

@kpdecker
Copy link

Accidentally did something like the following:

      validate: {
        payload: {
          data: mySchema.data
        }
      },

Where mySchema.data is undefined. This threw the following:

[Error: Invalid schema content: ]
Error: Invalid schema content:
    at Object.exports.assert (mycode/node_modules/hapi/node_modules/hoek/lib/index.js:731:11)
    at Object.exports.schema (mycode/node_modules/hapi/node_modules/joi/lib/cast.js:66:10)
    at internals.Object.keys (mycode/node_modules/hapi/node_modules/joi/lib/object.js:282:25)
    at Object.exports.schema (mycode/node_modules/hapi/node_modules/joi/lib/cast.js:47:33)
    at root.compile (mycode/node_modules/hapi/node_modules/joi/lib/index.js:113:21)
    at Object.internals.compileRule (mycode/node_modules/hapi/lib/route.js:256:88)
    at mycode/node_modules/hapi/lib/route.js:98:38
    at Array.forEach (native)
    at new module.exports.internals.Route (mycode/node_modules/hapi/lib/route.js:96:47)
    at internals.Connection._addRoute (mycode/node_modules/hapi/lib/connection.js:361:17)

Which does not provide much that's actionable. Ideally there would be some sort of reference to the data field and potentially the fact that this is the payload structure (although that would likely need to be in hapi vs. joi, hapi hapi joi joi).

@Marsup Marsup added the request label Oct 13, 2015
@Marsup Marsup self-assigned this Oct 13, 2015
@Marsup
Copy link
Collaborator

Marsup commented Oct 13, 2015

Hapi should report that it's payload. I'll think about it but I suspect it would be an awful amount of code for very little gain (because this rarely happens).

@kpdecker
Copy link
Author

That it rarely happens if more of a reason to include specific information in the error message because people do not know how to deal with it when it happens? It's unlikely that you'd catch every case that an init error can occur, but if there are known cases that require the user to hack on files in node_modules to figure out what exactly broke, we should fix them.

Can be as simple as adding try/catch combos to extend the error? Ex:

        var key = children[c];
        child = schema[key];

        try {
            var cast = Cast.schema(child);
            topo.add({ key: key, schema: cast }, { after: cast._refs, group: key });
        } catch (err) {
            throw new Error(`Key failed ${key}: ${err.message}`);
        }

Here https://github.com/hapijs/joi/blob/master/lib/object.js#L296

@Marsup Marsup added this to the 6.10.0 milestone Oct 15, 2015
@Marsup Marsup closed this as completed in cd466d5 Oct 15, 2015
@Marsup
Copy link
Collaborator

Marsup commented Oct 15, 2015

Unless you're in a hurry, I'll delay the next publish until I have a few more changes.

@kpdecker
Copy link
Author

No rush at all. I fixed my own problem, just filed the bug to help people who may be hit down the road. Thanks!

@hueniverse hueniverse added feature New functionality or improvement and removed request labels Sep 19, 2019
@lock
Copy link

lock bot commented Jan 9, 2020

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 9, 2020
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature New functionality or improvement
Projects
None yet
Development

No branches or pull requests

3 participants