GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — lib: assert.throws('string', TypeError, 'whatever') passes when it shouldn't · Issue #275 · nodejs/node

lib: assert.throws('string', TypeError, 'whatever') passes when it shouldn't #275

New issue
Copy link
New issue
Copy link
Closed
Closed
lib: assert.throws('string', TypeError, 'whatever') passes when it shouldn't#275
Copy link

Description

@bnoordhuis
bnoordhuis
opened on Jan 9, 2015
Issue body actions
assert.throws('string', TypeError, 'whatever');  // should fail but doesn't

From here:

assert.throws() calls the first argument as a function. The result is a TypeError when the input is a string but it doesn't seem to check that the exception message matches.

Activity

  1. cjihrig commented on Jan 9, 2015

    @cjihrig
    cjihrig
    on Jan 9, 2015
    Contributor
    More actions

    The third argument isn't supposed to be validated is it? The documentation doesn't seem to imply that it should. To validate the exception message, the second argument should be a regex or function.

    The third argument should be included in the error message though, right? That doesn't seem to be happening.

  2. dougwilson commented on Jan 9, 2015

    @dougwilson
    dougwilson
    on Jan 9, 2015
    Member
    More actions

    The third argument is the message to put in the AssertionError, like like all the other stuff in assert (the last argument is the assertion message).

  3. dougwilson commented on Jan 9, 2015

    @dougwilson
    dougwilson
    on Jan 9, 2015
    Member
    More actions

    Checking the thrown exception message would be to give a string as the second argument, rather than a constructor (you can also provide a RegExp object as the second argument).

  4. cjihrig commented on Jan 9, 2015

    @cjihrig
    cjihrig
    on Jan 9, 2015
    Contributor
    More actions

    Expects block to throw an error. error can be constructor, RegExp or validation function.

    I don't think strings are supported as the second arguments.

    Is there a specific reason that the assert module doesn't do a better job at input validation? For example, instead of blindly treating the first argument to throws() as a function, maybe it should validate that it is actually a function.

  5. bnoordhuis commented on Jan 9, 2015

    @bnoordhuis
    bnoordhuis
    on Jan 9, 2015
    MemberAuthor
    More actions

    Alright, seems I was wrong about the third argument. Let me rephrase: assert.throws('string', TypeError) passes for the wrong reasons. I think it should either throw a TypeError ("first argument must be a function") or eval() the argument, like the assert functions in the SM and V8 test suites.

  6. cjihrig commented on Jan 9, 2015

    @cjihrig
    cjihrig
    on Jan 9, 2015
    Contributor
    More actions

    @bnoordhuis +1 on throwing on bad input. I'll work on this.

  7. caitp commented on Jan 9, 2015

    @caitp
    caitp
    on Jan 9, 2015
    Contributor
    More actions

    what if the assert library were just changed to eval() if the first argument is a string? mjsunit does it like this, it's convenient :> (as suggested above, I guess)

  8. cjihrig
    added a commit that references this issue on Jan 12, 2015

    assert: throw when block is not a function

    14dc917
  9. cjihrig commented on Jan 12, 2015

    @cjihrig
    cjihrig
    on Jan 12, 2015
    Contributor
    More actions

    Closed in 14dc917

  10. cjihrig
    closed this as completedon Jan 12, 2015
  11. caitp commented on Jan 12, 2015

    @caitp
    caitp
    on Jan 12, 2015
    Contributor
    More actions

    Think I like the v8 behavior better there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.