Skip to content
This repository has been archived by the owner on Jul 8, 2020. It is now read-only.

Commit

Permalink
fix: allow snapshots in shorter transpiled files
Browse files Browse the repository at this point in the history
If a source file had `n` lines and was transpiled to a JavaScript
file with `m` lines with `m < n`, and one tried to set a snapshot
on a line between `m+1` and `n` in the original source file,
setting the snapshot would incorrectly fail with an error stating
that the requested line was beyond the size of the file.

Fixes: googleapis#464
  • Loading branch information
DominicKramer committed Aug 28, 2018
1 parent a136e14 commit 4e53557
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
30 changes: 15 additions & 15 deletions src/agent/v8/inspector-debugapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,21 +308,6 @@ export class InspectorDebugApi implements debugapi.DebugApi {
utils.messages.SOURCE_FILE_AMBIGUOUS);
}

// TODO: Address the case where `breakpoint.location` is `null`.
// TODO: Address the case where `fileStats[matchingScript]` is `null`.
if ((breakpoint.location as stackdriver.SourceLocation).line >=
(this.fileStats[matchingScript] as FileStats).lines) {
return utils.setErrorStatusAndCallback(
cb, breakpoint, StatusMessage.BREAKPOINT_SOURCE_LOCATION,
utils.messages.INVALID_LINE_NUMBER + matchingScript + ':' +
(breakpoint.location as stackdriver.SourceLocation).line +
'. Loaded script contained ' +
(this.fileStats[matchingScript] as FileStats).lines +
' lines. Please ensure' +
' that the snapshot was set in the same code version as the' +
' deployed source.');
}

// The breakpoint protobuf message presently doesn't have a column
// property but it may have one in the future.
// TODO: Address the case where `breakpoint.location` is `null`.
Expand All @@ -339,6 +324,21 @@ export class InspectorDebugApi implements debugapi.DebugApi {
column += debugapi.MODULE_WRAP_PREFIX_LENGTH - 1;
}

// TODO: Address the case where `breakpoint.location` is `null`.
// TODO: Address the case where `fileStats[matchingScript]` is `null`.
if ((breakpoint.location as stackdriver.SourceLocation).line >=
(this.fileStats[matchingScript] as FileStats).lines) {
return utils.setErrorStatusAndCallback(
cb, breakpoint, StatusMessage.BREAKPOINT_SOURCE_LOCATION,
utils.messages.INVALID_LINE_NUMBER + matchingScript + ':' +
(breakpoint.location as stackdriver.SourceLocation).line +
'. Loaded script contained ' +
(this.fileStats[matchingScript] as FileStats).lines +
' lines. Please ensure' +
' that the snapshot was set in the same code version as the' +
' deployed source.');
}

const result =
this.setAndStoreBreakpoint(breakpoint, line, column, matchingScript);
if (!result) {
Expand Down
26 changes: 13 additions & 13 deletions src/agent/v8/legacy-debugapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,19 +290,6 @@ export class V8DebugApi implements debugapi.DebugApi {
utils.messages.SOURCE_FILE_AMBIGUOUS);
}

// TODO: Address the case where `fileStats[matchingScript]` is `null`.
if ((breakpoint.location as stackdriver.SourceLocation).line >=
(this.fileStats[matchingScript] as FileStats).lines) {
return utils.setErrorStatusAndCallback(
cb, breakpoint, StatusMessage.BREAKPOINT_SOURCE_LOCATION,
utils.messages.INVALID_LINE_NUMBER + matchingScript + ':' +
(breakpoint.location as stackdriver.SourceLocation).line +
'. Loaded script contained ' +
(this.fileStats[matchingScript] as FileStats).lines +
' lines. Please ensure' +
' that the snapshot was set in the same code version as the' +
' deployed source.');
}
// The breakpoint protobuf message presently doesn't have a column property
// but it may have one in the future.
// TODO: Address the case where `breakpoint.location` is `null`.
Expand All @@ -320,6 +307,19 @@ export class V8DebugApi implements debugapi.DebugApi {
column += debugapi.MODULE_WRAP_PREFIX_LENGTH - 1;
}

// TODO: Address the case where `fileStats[matchingScript]` is `null`.
if (line >= (this.fileStats[matchingScript] as FileStats).lines) {
return utils.setErrorStatusAndCallback(
cb, breakpoint, StatusMessage.BREAKPOINT_SOURCE_LOCATION,
utils.messages.INVALID_LINE_NUMBER + matchingScript + ':' +
(breakpoint.location as stackdriver.SourceLocation).line +
'. Loaded script contained ' +
(this.fileStats[matchingScript] as FileStats).lines +
' lines. Please ensure' +
' that the snapshot was set in the same code version as the' +
' deployed source.');
}

const v8bp = this.setByRegExp(matchingScript, line, column);
if (!v8bp) {
return utils.setErrorStatusAndCallback(
Expand Down

0 comments on commit 4e53557

Please sign in to comment.