Code Monkey home page Code Monkey logo

assert's People

Contributors

jbphet avatar jessegreenberg avatar jonathanolson avatar phet-dev avatar pixelzoom avatar samreid avatar zepumph avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

assert's Issues

Use console.error instead of console.log

In https://github.com/phetsims/phet-io-wrappers/issues/506#issuecomment-1561656667 @zepumph said:

Perhaps assert should console.error instead of console.log

I agree we should use console.error instead of console.log. Here's a picture of a test assertion with assert the way it is now:

image

Using console.error, it looks like this:

image

And you can pop open the triangle like so:

image

@zepumph or @jonathanolson ok to commit this change? Or should we check in at dev meeting today?

Lint rule should forbid string literals in assert()

During phetsims/scenery#1407 I noticed around 10 occurrences like:

assert && assert( 'Need an active Node to update line width' );

Note that the string 'Need an active Node to update line width' is truthy, so this is equivalent to calling assert && assert(true) with no error message. Therefore it will never trigger. This can probably be also caught through type checking, but the type signature must allow string|null (for cases like assert(this.myNullableString,'string should not be null by now) so it may not be trivial. But a bad-text lint rule would be very easy. Here are the current failures:

Running "lint-everything" task

/Users/samreid/apache-document-root/main/circuit-construction-kit-common/js/view/CircuitElementNumberControl.ts
  84:15  error  Line contains bad text: 'assert( ''  bad-text

/Users/samreid/apache-document-root/main/equality-explorer/js/common/view/ObjectPicker.js
  368:21  error  Line contains bad text: 'assert( ''  bad-text

/Users/samreid/apache-document-root/main/neuron/js/neuron/model/NeuronModel.js
   852:17  error  Line contains bad text: 'assert( ''  bad-text
  1073:19  error  Line contains bad text: 'assert( ''  bad-text

/Users/samreid/apache-document-root/main/scenery-phet/js/NumberPicker.js
  532:21  error  Line contains bad text: 'assert( ''  bad-text

/Users/samreid/apache-document-root/main/scenery/js/input/SimpleDragHandler.js
  343:15  error  Line contains bad text: 'assert( ''  bad-text

/Users/samreid/apache-document-root/main/scenery/js/listeners/KeyboardDragListener.ts
  886:17  error  Line contains bad text: 'assert( ''  bad-text

/Users/samreid/apache-document-root/main/scenery/js/nodes/WebGLNode.ts
  152:15  error  Line contains bad text: 'assert( ''  bad-text

/Users/samreid/apache-document-root/main/scenery/js/overlays/HighlightOverlay.ts
  652:17  error  Line contains bad text: 'assert( ''  bad-text
  676:15  error  Line contains bad text: 'assert( ''  bad-text

✖ 10 problems (10 errors, 0 warnings)

Warning: 10 errors and 0 warnings Use --force to continue.

Should assert be an ES6 module?

In phetsims/chipper#912 we discussed converting assert to an ES6 module.

we would be able to use assert in phet-io wrappers (if we add a build step that traverses modules).

We even discussed converting assert and initialize-globals and _ to be loaded via modules. It's not clear whether we would miss the ability to just access them as globals.

assert and QSM are both used in the phet-io front end library, and may need consideration before turning into modules. That said, devs didn't mind seeing these transformed.

Webstorm has been very nice at automatically and semi-automatically adding imports for ES6 modules as needed. Still, I'm not sure of the benefits vs risks/costs for this issue. Leaving unassigned for now.

Chrome dev tools no longer pauses stack frames for iframe code

Google chrome dev tools used to pause with a navigable stack frame for iframe assertion failures. However, in the last few months, it instead prints the iframe stack trace to the console instead, and you cannot access any of the stack frames or variable values. To work around this, I have been temporarily adding debugger to assert.js, but this feels hackish. I wonder if we should (a) find out how to get chrome to pause stack frames again in iframes or (b) add code to assert.js that basically says:

      console && console.log && console.log( 'Assertion failed: ' + message );
      if (isInIFrameCode()){
        debugger;
      }
      throw new Error( 'Assertion failed: ' + message );

Print assertion to the console before erroring out?

When running with ?ea and the console open, it takes me longer than necessary to find the assertion message. How do others get around (or not have) this problem?

Should we print the assertion error to the console before throwing error?

Adding this line to assert.js looks like it will make my life much easier:

console.log( 'Assertion failed: ' + message );

Assigned to @jonathanolson for discussion, but @pixelzoom @jbphet @jessegreenberg and @phetsims/aadish may want to discuss as well.

Update the assert error to handle a lack of message

From dev meeting today. We don't require that assertion messages are included in every assert call. Therefore it would be nice if the error message handled this case without saying: Assertion failed: undefined.

@jonathanolson had the recommendation to try to add the lineNum/file that the assert came from, otherwise we can just say Assertion failed or something.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.