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

CODEBASE: Suppress false-positive console errors caused by RamCalculation.test.ts #2002

Conversation

catloversg
Copy link
Contributor

While running Jest tests, I see these console errors:

  console.error
    validate.errors: [
      {
        instancePath: '',
        schemaPath: '#/type',
        keyword: 'type',
        params: { type: 'object' },
        message: 'must be object'
      }
    ]

       8 | function assertAndSanitize(data: unknown, validate: ValidateFunction<unknown>): void {
       9 |   if (!validate(data)) {
    > 10 |     console.error("validate.errors:", validate.errors);
         |             ^
      11 |     // validate.errors is an array of objects, so we need to use JSON.stringify.
      12 |     throw new Error(JSON.stringify(validate.errors));
      13 |   }

      at error (src/JsonSchema/JSONSchemaAssertion.ts:10:13)
      at assertAndSanitize (src/JsonSchema/JSONSchemaAssertion.ts:20:3)
      at src/NetscriptFunctions/UserInterface.ts:122:35
      at func (src/Netscript/APIWrapper.ts:82:16)
      at fn (test/jest/Netscript/RamCalculation.test.ts:49:7)
      at tryFunction (test/jest/Netscript/RamCalculation.test.ts:100:7)
      at Object.combinedRamCheck (test/jest/Netscript/RamCalculation.test.ts:132:37)

  console.error
    validate.errors: [
      {
        instancePath: '',
        schemaPath: '#/type',
        keyword: 'type',
        params: { type: 'object' },
        message: 'must be object'
      }
    ]

       8 | function assertAndSanitize(data: unknown, validate: ValidateFunction<unknown>): void {
       9 |   if (!validate(data)) {
    > 10 |     console.error("validate.errors:", validate.errors);
         |             ^
      11 |     // validate.errors is an array of objects, so we need to use JSON.stringify.
      12 |     throw new Error(JSON.stringify(validate.errors));
      13 |   }

      at error (src/JsonSchema/JSONSchemaAssertion.ts:10:13)
      at assertAndSanitize (src/JsonSchema/JSONSchemaAssertion.ts:20:3)
      at src/NetscriptFunctions/UserInterface.ts:122:35
      at func (src/Netscript/APIWrapper.ts:82:16)
      at fn (test/jest/Netscript/RamCalculation.test.ts:49:7)
      at tryFunction (test/jest/Netscript/RamCalculation.test.ts:101:7)
      at Object.combinedRamCheck (test/jest/Netscript/RamCalculation.test.ts:132:37)

  console.error
    validate.errors: [
      {
        instancePath: '',
        schemaPath: '#/type',
        keyword: 'type',
        params: { type: 'object' },
        message: 'must be object'
      }
    ]

       8 | function assertAndSanitize(data: unknown, validate: ValidateFunction<unknown>): void {
       9 |   if (!validate(data)) {
    > 10 |     console.error("validate.errors:", validate.errors);
         |             ^
      11 |     // validate.errors is an array of objects, so we need to use JSON.stringify.
      12 |     throw new Error(JSON.stringify(validate.errors));
      13 |   }

      at error (src/JsonSchema/JSONSchemaAssertion.ts:10:13)
      at assertAndSanitize (src/JsonSchema/JSONSchemaAssertion.ts:20:3)
      at src/NetscriptFunctions/UserInterface.ts:122:35
      at func (src/Netscript/APIWrapper.ts:82:16)
      at fn (test/jest/Netscript/RamCalculation.test.ts:49:7)
      at tryFunction (test/jest/Netscript/RamCalculation.test.ts:102:7)
      at Object.combinedRamCheck (test/jest/Netscript/RamCalculation.test.ts:132:37)

  console.error
    validate.errors: [
      {
        instancePath: '',
        schemaPath: '#/type',
        keyword: 'type',
        params: { type: 'object' },
        message: 'must be object'
      }
    ]

       8 | function assertAndSanitize(data: unknown, validate: ValidateFunction<unknown>): void {
       9 |   if (!validate(data)) {
    > 10 |     console.error("validate.errors:", validate.errors);
         |             ^
      11 |     // validate.errors is an array of objects, so we need to use JSON.stringify.
      12 |     throw new Error(JSON.stringify(validate.errors));
      13 |   }

      at error (src/JsonSchema/JSONSchemaAssertion.ts:10:13)
      at assertAndSanitize (src/JsonSchema/JSONSchemaAssertion.ts:34:3)
      at src/NetscriptFunctions/UserInterface.ts:139:32
      at func (src/Netscript/APIWrapper.ts:82:16)
      at fn (test/jest/Netscript/RamCalculation.test.ts:49:7)
      at tryFunction (test/jest/Netscript/RamCalculation.test.ts:100:7)
      at Object.combinedRamCheck (test/jest/Netscript/RamCalculation.test.ts:132:37)

  console.error
    validate.errors: [
      {
        instancePath: '',
        schemaPath: '#/type',
        keyword: 'type',
        params: { type: 'object' },
        message: 'must be object'
      }
    ]

       8 | function assertAndSanitize(data: unknown, validate: ValidateFunction<unknown>): void {
       9 |   if (!validate(data)) {
    > 10 |     console.error("validate.errors:", validate.errors);
         |             ^
      11 |     // validate.errors is an array of objects, so we need to use JSON.stringify.
      12 |     throw new Error(JSON.stringify(validate.errors));
      13 |   }

      at error (src/JsonSchema/JSONSchemaAssertion.ts:10:13)
      at assertAndSanitize (src/JsonSchema/JSONSchemaAssertion.ts:34:3)
      at src/NetscriptFunctions/UserInterface.ts:139:32
      at func (src/Netscript/APIWrapper.ts:82:16)
      at fn (test/jest/Netscript/RamCalculation.test.ts:49:7)
      at tryFunction (test/jest/Netscript/RamCalculation.test.ts:101:7)
      at Object.combinedRamCheck (test/jest/Netscript/RamCalculation.test.ts:132:37)

  console.error
    validate.errors: [
      {
        instancePath: '',
        schemaPath: '#/type',
        keyword: 'type',
        params: { type: 'object' },
        message: 'must be object'
      }
    ]

       8 | function assertAndSanitize(data: unknown, validate: ValidateFunction<unknown>): void {
       9 |   if (!validate(data)) {
    > 10 |     console.error("validate.errors:", validate.errors);
         |             ^
      11 |     // validate.errors is an array of objects, so we need to use JSON.stringify.
      12 |     throw new Error(JSON.stringify(validate.errors));
      13 |   }

      at error (src/JsonSchema/JSONSchemaAssertion.ts:10:13)
      at assertAndSanitize (src/JsonSchema/JSONSchemaAssertion.ts:34:3)
      at src/NetscriptFunctions/UserInterface.ts:139:32
      at func (src/Netscript/APIWrapper.ts:82:16)
      at fn (test/jest/Netscript/RamCalculation.test.ts:49:7)
      at tryFunction (test/jest/Netscript/RamCalculation.test.ts:102:7)
      at Object.combinedRamCheck (test/jest/Netscript/RamCalculation.test.ts:132:37)

In test\jest\Netscript\RamCalculation.test.ts, we try to run all NS APIs and check bugs of RAM cost. We intentionally ignore all errors when running those APIs (we call them without any input data). This is fine for most APIs, but with some APIs that involve checking JSON Schema, it prints many errors in the console. This PR suppresses those false-positive errors.

@d0sboots d0sboots merged commit 7f44342 into bitburner-official:dev Mar 7, 2025
5 checks passed
@catloversg catloversg deleted the pull-request/codebase/suppress-false-positive-console-errors-caused-by-RamCalculation.test.ts branch March 8, 2025 10:40
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

Successfully merging this pull request may close these issues.

2 participants