File tree Expand file tree Collapse file tree 8 files changed +27
-21
lines changed
Expand file tree Collapse file tree 8 files changed +27
-21
lines changed Original file line number Diff line number Diff line change @@ -1248,8 +1248,9 @@ SourceView--archive-parsing-error-when-obtaining-source =
12481248# Variables:
12491249# $url (String) - The URL of the JS source file.
12501250# $sourceUuid (number) - The UUID of the JS source file.
1251+ # $errorMessage (String) - The raw internal error message, not localized
12511252SourceView--not-in-browser-error-when-obtaining-js-source =
1252- The browser was unable to obtain the source file for { $url } with sourceUuid { $sourceUuid } .
1253+ The browser was unable to obtain the source file for { $url } with sourceUuid { $sourceUuid } : { $errorMessage } .
12531254
12541255## Toggle buttons in the top right corner of the bottom box
12551256
Original file line number Diff line number Diff line change @@ -85,7 +85,7 @@ export interface BrowserConnection {
8585 column : number | null
8686 ) : Promise < void > ;
8787
88- getJSSource ( sourceUuid : string ) : Promise < string | null > ;
88+ getJSSource ( sourceUuid : string ) : Promise < string > ;
8989}
9090
9191/**
@@ -236,7 +236,7 @@ class BrowserConnectionImpl implements BrowserConnection {
236236 * Fetches JavaScript source code from the browser using the source UUID.
237237 * This method requires WebChannel version 6 or higher (Firefox 145+).
238238 */
239- async getJSSource ( sourceUuid : string ) : Promise < string | null > {
239+ async getJSSource ( sourceUuid : string ) : Promise < string > {
240240 if ( ! this . _webChannelSupportsGetJSSource ) {
241241 throw new Error (
242242 "Can't use getJSSource in Firefox versions with the old WebChannel."
@@ -247,9 +247,14 @@ class BrowserConnectionImpl implements BrowserConnection {
247247 // fetching multiple sources, we only fetch one at a time currently.
248248 // TODO: Change this to fetch multiple JS sources at the load time or while
249249 // we share the profile.
250- return getJSSourcesViaWebChannel ( [ sourceUuid ] ) . then (
251- ( sources ) => sources [ 0 ]
252- ) ;
250+ return getJSSourcesViaWebChannel ( [ sourceUuid ] ) . then ( ( sources ) => {
251+ const source = sources [ 0 ] ;
252+ if ( 'error' in source ) {
253+ throw new Error ( source . error ) ;
254+ }
255+
256+ return source . sourceText ;
257+ } ) ;
253258 }
254259}
255260
Original file line number Diff line number Diff line change @@ -147,7 +147,8 @@ type GetSymbolTableResponse = SymbolTableAsTuple;
147147type QuerySymbolicationApiResponse = string ;
148148type GetPageFaviconsResponse = Array < FaviconData | null > ;
149149type OpenScriptInTabDebuggerResponse = void ;
150- type GetJSSourcesResponse = Array < string | null > ;
150+ type GetJSSourceReponseItem = { sourceText : string } | { error : string } ;
151+ type GetJSSourcesResponse = Array < GetJSSourceReponseItem > ;
151152
152153// TypeScript function overloads for request/response pairs.
153154function _sendMessageWithResponse (
@@ -387,7 +388,7 @@ export async function showFunctionInDevtoolsViaWebChannel(
387388
388389export async function getJSSourcesViaWebChannel (
389390 sourceUuids : Array < string >
390- ) : Promise < Array < string | null > > {
391+ ) : Promise < Array < GetJSSourceReponseItem > > {
391392 return _sendMessageWithResponse ( {
392393 type : 'GET_JS_SOURCES' ,
393394 sourceUuids,
Original file line number Diff line number Diff line change @@ -113,13 +113,13 @@ export function CodeErrorOverlay({ errors }: CodeErrorOverlayProps) {
113113 ) ;
114114 }
115115 case 'NOT_PRESENT_IN_BROWSER' : {
116- const { sourceUuid, url } = error ;
116+ const { sourceUuid, url, errorMessage } = error ;
117117 return (
118118 < Localized
119119 id = "SourceView--not-in-browser-error-when-obtaining-js-source"
120- vars = { { url, sourceUuid } }
120+ vars = { { url, sourceUuid, errorMessage } }
121121 >
122- < li > { `The browser was unable to obtain the source file for ${ url } with sourceUuid ${ sourceUuid } ` } </ li >
122+ < li > { `The browser was unable to obtain the source file for ${ url } with sourceUuid ${ sourceUuid } : ${ errorMessage } ` } </ li >
123123 </ Localized >
124124 ) ;
125125 }
Original file line number Diff line number Diff line change @@ -618,8 +618,10 @@ describe('fetchSource', function () {
618618 type : 'ERROR' ,
619619 errors : [
620620 {
621- type : 'BROWSER_API_ERROR' ,
622- apiErrorMessage : `Source not found for source with ID: ${ TEST_SOURCE_UUID } ` ,
621+ type : 'NOT_PRESENT_IN_BROWSER' ,
622+ sourceUuid : 'ff6d24c3-b8f5-45cd-a7d3-b643b3292e41' ,
623+ url : '/path/to/script.js' ,
624+ errorMessage : `Error: Source not found for source with ID: ${ TEST_SOURCE_UUID } ` ,
623625 } ,
624626 {
625627 type : 'NO_KNOWN_CORS_URL' ,
Original file line number Diff line number Diff line change @@ -335,6 +335,7 @@ export type SourceCodeLoadingError =
335335 type : 'NOT_PRESENT_IN_BROWSER' ;
336336 sourceUuid : string ;
337337 url : string ;
338+ errorMessage : string ;
338339 } ;
339340
340341export type ProfileSpecificUrlState = {
Original file line number Diff line number Diff line change @@ -99,16 +99,12 @@ export async function fetchSource(
9999 source : response ,
100100 } ;
101101 }
102-
102+ } catch ( e ) {
103103 errors . push ( {
104104 type : 'NOT_PRESENT_IN_BROWSER' ,
105105 sourceUuid,
106106 url : file ,
107- } ) ;
108- } catch ( e ) {
109- errors . push ( {
110- type : 'BROWSER_API_ERROR' ,
111- apiErrorMessage : e . message ,
107+ errorMessage : e . toString ( ) ,
112108 } ) ;
113109 }
114110 }
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ export interface ExternalCommunicationDelegate {
2424 requestJson : string
2525 ) : Promise < string > ;
2626
27- fetchJSSourceFromBrowser ( source : string ) : Promise < string | null > ;
27+ fetchJSSourceFromBrowser ( source : string ) : Promise < string > ;
2828}
2929
3030export type ApiQueryResult < T > =
@@ -163,7 +163,7 @@ export class RegularExternalCommunicationDelegate
163163 return browserConnection . querySymbolicationApi ( path , requestJson ) ;
164164 }
165165
166- fetchJSSourceFromBrowser ( source : string ) : Promise < string | null > {
166+ fetchJSSourceFromBrowser ( source : string ) : Promise < string > {
167167 const browserConnection = this . _browserConnection ;
168168 if ( browserConnection === null ) {
169169 throw new Error ( 'No connection to the browser.' ) ;
You can’t perform that action at this time.
0 commit comments