Skip to content

Respect p5.disableFriendlyErrors setting when overriding p5 global variables #7819

Closed
@quinton-ashley

Description

@quinton-ashley

Most appropriate sub-area of p5.js?

  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • Build process
  • Unit testing
  • Internationalization
  • Friendly errors
  • Other (specify if possible)

p5.js version

1.11.7

Web browser and version

Chrome

Operating system

macOS

Steps to reproduce this

This is a regression, the problem does not occur in previous version of p5.

User's p5.disableFriendlyErrors setting should be respected when overriding p5 global variables.

Example:
https://editor.p5js.org/quinton-ashley/sketches/ca-G8kD1O

The if statement requiring that p5.disableFriendlyErrors be false is correct, but this also needs to be checked before printing the error message, since users could set p5.disableFriendlyErrors = true after that.

if (!p5.disableFriendlyErrors && ...) {
  try {
    Object.defineProperty(globalObject, prop, {
      configurable: true,
      enumerable: true,
      get: function get() {
        return value;
      },
      set: function set(newValue) {
        Object.defineProperty(globalObject, prop, {
          configurable: true,
          enumerable: true,
          value: newValue,
          writable: true
        });


        log('You just changed the value of "'.concat(prop, '", which was a p5 function. This could cause problems later if you\'re not careful.'));
      }
    });

// ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions