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

feat: log unexpected GraphQL errors #2084

Merged
merged 1 commit into from
Nov 11, 2022
Merged

Conversation

n1ru4l
Copy link
Collaborator

@n1ru4l n1ru4l commented Nov 11, 2022

closes #1584

@changeset-bot
Copy link

changeset-bot bot commented Nov 11, 2022

⚠️ No Changeset found

Latest commit: 2ae48ff

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Comment on lines +242 to +257
maskError: (error, message) => {
const newError = maskErrorFn(
{
error,
message,
isDev: this.maskedErrorsOpts?.isDev ?? false,
},
message,
)

if (newError !== error) {
this.logger.error(error)
}

return newError
},
Copy link
Collaborator Author

@n1ru4l n1ru4l Nov 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case error masking is disabled that means that every error is an expected error - thus we shouldn't log any error.

Comment on lines +4 to +45
const logLevelScores: Record<LogLevel | 'silent', number> = {
debug: 0,
info: 1,
warn: 2,
error: 3,
silent: 4,
}

// eslint-disable-next-line @typescript-eslint/no-empty-function
const noop = () => {}

/**
* utility for creating a conditional logger for tests.
*/
export const createCustomLogger = (
logLevel: LogLevel | 'silent' = globalThis?.process.env['DEBUG'] === '1'
? 'debug'
: 'info',
) => {
const score = logLevelScores[logLevel]
return {
debug: score > logLevelScores.debug ? noop : debugLog,
info: score > logLevelScores.info ? noop : infoLog,
warn: score > logLevelScores.warn ? noop : warnLog,
error: score > logLevelScores.error ? noop : errorLog,
}
}

const consoleLog = (...args: Array<any>) => console.log(...args)

const debugLog = console.debug
? (...args: Array<any>) => console.debug(...args)
: consoleLog
const infoLog = console.info
? (...args: Array<any>) => console.info(...args)
: consoleLog
const warnLog = console.warn
? (...args: Array<any>) => console.warn(...args)
: consoleLog
const errorLog = console.error
? (...args: Array<any>) => console.error(...args)
: consoleLog
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kamilkisiela We can use this logger implementation in hive in case my proposal does not make it into yoga v3.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 11, 2022

✅ Benchmark Results

     ✓ no_errors
     ✓ expected_result

     checks.........................: 100.00% ✓ 159798      ✗ 0    
     data_received..................: 24 MB   794 kB/s
     data_sent......................: 9.2 MB  306 kB/s
     http_req_blocked...............: avg=1.29µs   min=800ns   med=1.1µs   max=331.9µs p(90)=1.6µs   p(95)=2µs    
     http_req_connecting............: avg=1ns      min=0s      med=0s      max=131.4µs p(90)=0s      p(95)=0s     
   ✓ http_req_duration..............: avg=294.36µs min=195.7µs med=262.5µs max=27.54ms p(90)=328.3µs p(95)=351.3µs
       { expected_response:true }...: avg=294.36µs min=195.7µs med=262.5µs max=27.54ms p(90)=328.3µs p(95)=351.3µs
     http_req_failed................: 0.00%   ✓ 0           ✗ 79899
     http_req_receiving.............: avg=20.47µs  min=11.2µs  med=18.4µs  max=8.37ms  p(90)=25.8µs  p(95)=28µs   
     http_req_sending...............: avg=8.1µs    min=4.1µs   med=6.1µs   max=1.83ms  p(90)=11µs    p(95)=11.9µs 
     http_req_tls_handshaking.......: avg=0s       min=0s      med=0s      max=0s      p(90)=0s      p(95)=0s     
     http_req_waiting...............: avg=265.78µs min=175µs   med=236.1µs max=27.48ms p(90)=294.9µs p(95)=315µs  
     http_reqs......................: 79899   2663.150149/s
     iteration_duration.............: avg=368.64µs min=253µs   med=334.3µs max=27.68ms p(90)=414.3µs p(95)=443.7µs
     iterations.....................: 79899   2663.150149/s
     vus............................: 1       min=1         max=1  
     vus_max........................: 1       min=1         max=1  

@github-actions
Copy link
Contributor

🚀 Website Preview

The latest changes to the website are available as preview in: https://260d9549.graphql-yoga.pages.dev

@n1ru4l n1ru4l merged commit 4e7d58e into main Nov 11, 2022
@n1ru4l n1ru4l deleted the feat-log-unexpected-errors branch November 11, 2022 12:27
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.

log unexpected errors in the server console by default
4 participants