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

Non-hash input should not raise errors #191

Open
BanzaiMan opened this issue Aug 6, 2020 · 0 comments
Open

Non-hash input should not raise errors #191

BanzaiMan opened this issue Aug 6, 2020 · 0 comments

Comments

@BanzaiMan
Copy link
Contributor

Problem

Non-hash input such as

n

should not throw errors (in the library, or 400's/500's in HTTP).

Current behavior

HTTP requests throw 500
$ curl -vs -X POST -d 'n' http://localhost:9292/v1/parse
*   Trying ::1:9292...
* TCP_NODELAY set
* Connected to localhost (::1) port 9292 (#0)
> POST /v1/parse HTTP/1.1
> Host: localhost:9292
> User-Agent: curl/7.65.3
> Accept: */*
> Content-Length: 1
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 1 out of 1 bytes
* Mark bundle as not supporting multiuse
< HTTP/1.1 500 Internal Server Error
< Content-Type: text/plain
< X-Content-Type-Options: nosniff
< Vary: Origin
< X-Rack-CORS: miss; no-origin
< Content-Length: 13548
<
NoMethodError: undefined method `opts' for "n":String
        /Users/asari/Development/src/travis-ci/travis-yml/lib/travis/yml/parts/part.rb:25:in `to_h'
        /Users/asari/Development/src/travis-ci/travis-yml/lib/travis/yml/parts.rb:10:in `load'
        /Users/asari/Development/src/travis-ci/travis-yml/lib/travis/yml.rb:108:in `load'
        /Users/asari/Development/src/travis-ci/travis-yml/lib/travis/yml/web/parse.rb:33:in `load'
        /Users/asari/Development/src/travis-ci/travis-yml/lib/travis/yml/web/parse.rb:26:in `handle'
        /Users/asari/Development/src/travis-ci/travis-yml/lib/travis/yml/web/parse.rb:19:in `block in '
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:1636:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:1636:in `block in compile!'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:987:in `block (3 levels) in route!'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:1006:in `route_eval'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:987:in `block (2 levels) in route!'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:1035:in `block in process_route'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:1033:in `catch'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:1033:in `process_route'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:985:in `block in route!'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:984:in `each'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:984:in `route!'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:1098:in `block in dispatch!'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:1072:in `block in invoke'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:1072:in `catch'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:1072:in `invoke'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:1095:in `dispatch!'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:919:in `block in call!'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:1072:in `block in invoke'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:1072:in `catch'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:1072:in `invoke'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:919:in `call!'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:908:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-protection-2.0.8.1/lib/rack/protection/xss_header.rb:18:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-protection-2.0.8.1/lib/rack/protection/path_traversal.rb:16:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-protection-2.0.8.1/lib/rack/protection/json_csrf.rb:26:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-protection-2.0.8.1/lib/rack/protection/base.rb:50:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-protection-2.0.8.1/lib/rack/protection/base.rb:50:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-protection-2.0.8.1/lib/rack/protection/frame_options.rb:31:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-2.2.3/lib/rack/null_logger.rb:11:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-2.2.3/lib/rack/head.rb:12:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/show_exceptions.rb:22:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:194:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:1951:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:966:in `forward'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:1052:in `route_missing'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:1001:in `route!'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:997:in `route!'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:1098:in `block in dispatch!'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:1072:in `block in invoke'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:1072:in `catch'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:1072:in `invoke'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:1095:in `dispatch!'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:919:in `block in call!'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:1072:in `block in invoke'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:1072:in `catch'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:1072:in `invoke'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:919:in `call!'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:908:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-protection-2.0.8.1/lib/rack/protection/xss_header.rb:18:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-protection-2.0.8.1/lib/rack/protection/path_traversal.rb:16:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-protection-2.0.8.1/lib/rack/protection/json_csrf.rb:26:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-protection-2.0.8.1/lib/rack/protection/base.rb:50:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-protection-2.0.8.1/lib/rack/protection/base.rb:50:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-protection-2.0.8.1/lib/rack/protection/frame_options.rb:31:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-2.2.3/lib/rack/null_logger.rb:11:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-2.2.3/lib/rack/head.rb:12:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/show_exceptions.rb:22:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:194:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:1951:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:966:in `forward'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:1052:in `route_missing'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:1001:in `route!'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:997:in `route!'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:1098:in `block in dispatch!'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:1072:in `block in invoke'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:1072:in `catch'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:1072:in `invoke'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:1095:in `dispatch!'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:919:in `block in call!'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:1072:in `block in invoke'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:1072:in `catch'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:1072:in `invoke'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:919:in `call!'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:908:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-protection-2.0.8.1/lib/rack/protection/xss_header.rb:18:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-protection-2.0.8.1/lib/rack/protection/path_traversal.rb:16:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-protection-2.0.8.1/lib/rack/protection/json_csrf.rb:26:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-protection-2.0.8.1/lib/rack/protection/base.rb:50:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-protection-2.0.8.1/lib/rack/protection/base.rb:50:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-protection-2.0.8.1/lib/rack/protection/frame_options.rb:31:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-2.2.3/lib/rack/null_logger.rb:11:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-2.2.3/lib/rack/head.rb:12:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/show_exceptions.rb:22:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:194:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:1951:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-cors-1.1.1/lib/rack/cors.rb:100:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-protection-2.0.8.1/lib/rack/protection/xss_header.rb:18:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-protection-2.0.8.1/lib/rack/protection/path_traversal.rb:16:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-protection-2.0.8.1/lib/rack/protection/json_csrf.rb:26:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-protection-2.0.8.1/lib/rack/protection/base.rb:50:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-protection-2.0.8.1/lib/rack/protection/base.rb:50:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-protection-2.0.8.1/lib/rack/protection/frame_options.rb:31:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-2.2.3/lib/rack/null_logger.rb:11:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-2.2.3/lib/rack/head.rb:12:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/show_exceptions.rb:22:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:194:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:1951:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-2.2.3/lib/rack/tempfile_reaper.rb:15:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-2.2.3/lib/rack/lint.rb:50:in `_call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-2.2.3/lib/rack/lint.rb:38:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-2.2.3/lib/rack/show_exceptions.rb:23:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-2.2.3/lib/rack/common_logger.rb:38:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:231:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-2.2.3/lib/rack/content_length.rb:17:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/puma-4.3.5/lib/puma/configuration.rb:228:in `call'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/puma-4.3.5/lib/puma/server.rb:713:in `handle_request'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/puma-4.3.5/lib/puma/server.rb:472:in `process_client'
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/puma-4.3.5/lib/puma/server.rb:328:in `block in run'
* Connection #0 to host localhost left intact
        /Users/asari/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/puma-4.3.5/lib/puma/thread_pool.rb:134:in `block in spawn_thread'

Expected behavior

Return a data structure indicating an error in the input, e.g.,

$ curl -s -X POST -d 'n' http://localhost:9292/v1/parse | jq .
{
  "version": "v1",
  "messages": [
    {
      "type": "config",
      "level": "warn",
      "key": "root",
      "code": "unprocessable_data",
      "args": {
        "key": "n",
        "value": nil
      },
      "line": 0
    },
    {
      "type": "config",
      "level": "info",
      "key": "root",
      "code": "default",
      "args": {
        "key": "language",
        "default": "ruby"
      }
    },
    {
      "type": "config",
      "level": "info",
      "key": "root",
      "code": "default",
      "args": {
        "key": "os",
        "default": "linux"
      }
    },
    {
      "type": "config",
      "level": "info",
      "key": "root",
      "code": "default",
      "args": {
        "key": "dist",
        "default": "xenial"
      }
    }
  ],
  "full_messages": [
    "[warn] on root: unprocessable data \"n\"",
    "[info] on root: missing language, using the default \"ruby\"",
    "[info] on root: missing os, using the default \"linux\"",
    "[info] on root: missing dist, using the default \"xenial\""
  ],
  "config": {
    "a": "b",
    "language": "ruby",
    "os": [
      "linux"
    ],
    "dist": "xenial"
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant