@@ -30,6 +30,12 @@ export type AppInfo = {
3030
3131export class AppInfoError extends Error { }
3232
33+ const MISSING_MANIFEST = {
34+ name : undefined ,
35+ sourceCodeUrl : undefined ,
36+ manifestFound : false ,
37+ } ;
38+
3339export async function getAppInfo ( location : Location ) : Promise < AppInfo > {
3440 if ( location . type === "url" ) {
3541 try {
@@ -72,19 +78,10 @@ async function getManifestInfoFromUrl(
7278 }
7379 const response = await fetch ( url + "manifest.toml" ) ;
7480 if ( ! response . ok ) {
75- return {
76- name : "Unknown (running from URL)" ,
77- sourceCodeUrl : undefined ,
78- manifestFound : false ,
79- } ;
81+ console . error ( "Missing manifest.toml (from URL)" ) ;
82+ return { ...MISSING_MANIFEST , name : "Unknown (running from URL)" } ;
8083 }
81- const body = await response . text ( ) ;
82- const parsed = tomlParse ( body ) ;
83- return {
84- name : parsed . name || "No entry in manifest.toml (running from URL)" ,
85- sourceCodeUrl : parsed . source_code_url ,
86- manifestFound : true ,
87- } ;
84+ return tomlParse ( await response . text ( ) ) ;
8885}
8986
9087async function getIconInfoFromUrl (
@@ -117,26 +114,24 @@ function getManifestInfoFromDir(
117114) : ManifestInfo {
118115 const tomlBuffer = readFileBuffer ( path . join ( dir , "manifest.toml" ) ) ;
119116 if ( tomlBuffer === null ) {
120- return {
121- name : fallbackName ,
122- sourceCodeUrl : undefined ,
123- manifestFound : false ,
124- } ;
117+ console . error ( "Missing manifest.toml (from DIR)" ) ;
118+ return { ...MISSING_MANIFEST , name : fallbackName } ;
125119 }
126- const parsed = tomlParse ( tomlBuffer . toString ( ) ) ;
127- const name = parsed . name || fallbackName ;
128- return {
129- name,
130- sourceCodeUrl : parsed . source_code_url ,
131- manifestFound : true ,
132- } ;
120+ return tomlParse ( tomlBuffer . toString ( ) , fallbackName ) ;
133121}
134122
135- function tomlParse ( s : string ) : any {
123+ function tomlParse ( s : string , fallbackName : string ) : any {
136124 try {
137- return toml . parse ( s ) ;
125+ const parsed = toml . parse ( s ) ;
126+ return {
127+ name :
128+ parsed . name || fallbackName || "Missing name entry in manifest.toml" ,
129+ sourceCodeUrl : parsed . source_code_url || undefined ,
130+ manifestFound : true ,
131+ } ;
138132 } catch ( e ) {
139- throw new AppInfoError ( "Invalid manifest.toml, please check the format" ) ;
133+ console . error ( "Failed to parse manifest.toml, please check the format!" ) ;
134+ return { ...MISSING_MANIFEST , name : fallbackName } ;
140135 }
141136}
142137
0 commit comments