-
Notifications
You must be signed in to change notification settings - Fork 821
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
fix: handle missing package.json file when checking for version #2450
fix: handle missing package.json file when checking for version #2450
Conversation
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const version = require(path.join(baseDir, 'package.json')).version; | ||
const version = existsSync(packageJsonPath) ? require(packageJsonPath).version : undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
even if a file exists it may be not readable (e.g. access rights). What about using a try/catch block instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done 👍
Codecov Report
@@ Coverage Diff @@
## main #2450 +/- ##
==========================================
+ Coverage 92.71% 93.20% +0.48%
==========================================
Files 137 137
Lines 4996 5002 +6
Branches 1057 1057
==========================================
+ Hits 4632 4662 +30
+ Misses 364 340 -24
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it's quite obvious for most people, but I'd add a comment somewhere that we are dealing with packages here for which we haven't detected a version at all. The describe
kinda point in that direction, but the setup doesn't make that clear.
Something like
describe('_onRequire - module version is not available', () => {
// For all of these cases, there is no indication of the actual module version,
// so we require there to be a wildcard supported version.
@rauno56 👍 |
@nozik You'll need to rebase the PR (or give us access to your fork so we can do it for you) |
@vmarchaud done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, just some suggestion for tests description
packages/opentelemetry-instrumentation/test/node/InstrumentationBase.test.ts
Outdated
Show resolved
Hide resolved
packages/opentelemetry-instrumentation/test/node/InstrumentationBase.test.ts
Outdated
Show resolved
Hide resolved
packages/opentelemetry-instrumentation/test/node/InstrumentationBase.test.ts
Outdated
Show resolved
Hide resolved
packages/opentelemetry-instrumentation/test/node/InstrumentationBase.test.ts
Outdated
Show resolved
Hide resolved
@obecny Done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, thx for changes
Which problem is this PR solving?
package.json
file may be missing at runtime for a certain module. Currently OTEL crashes in this case, unnecessarily.Short description of the changes
package.json
file), we patch the module/file if and only if the supported versions contain a wildcard (*
). Until now, an exception was thrown, crashing the app.