Skip to content

Commit

Permalink
chore: add verbose app init log
Browse files Browse the repository at this point in the history
  • Loading branch information
zdm committed Dec 26, 2024
1 parent 6d64717 commit 219f8eb
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions lib/app/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ export default class Components {
for ( const component of Object.values( this.#components ).reverse() ) {
const res = await component.configure();

if ( !res.ok ) return result( [ res.status, `[${ component.id }] Failed to configure component: ${ res.statusText }` ] );
if ( !res.ok ) return result( [ res.status, `[${ component.id }] Failed to configure component. ${ res.statusText }` ] );
}

const components = this.#components;
Expand Down Expand Up @@ -359,7 +359,7 @@ export default class Components {
for ( const component of Object.values( this.#components ) ) {
const res = this.#validateComponentConfig( component );

if ( !res.ok ) return result( [ res.status, `[${ component.id }] Component config is not valid: ${ res.statusText }` ] );
if ( !res.ok ) return result( [ res.status, `[${ component.id }] Component config is not valid. ${ res.statusText }` ] );
}

// add components templates
Expand All @@ -379,7 +379,7 @@ export default class Components {
for ( const component of this ) {
const res = await component.install();

if ( !res.ok ) return result( [ res.status, `[${ component.id }] Failed to install component: ${ res.statusText }` ] );
if ( !res.ok ) return result( [ res.status, `[${ component.id }] Failed to install component. ${ res.statusText }` ] );
}

return result( 200 );
Expand All @@ -393,11 +393,11 @@ export default class Components {
// configure component instance
res = await component.configureInstance();

if ( !res.ok ) return result( [ res.status, `[${ component.id }] Failed to configure component instance: ${ res.statusText }` ] );
if ( !res.ok ) return result( [ res.status, `[${ component.id }] Failed to configure component instance. ${ res.statusText }` ] );

// validate component config
res = this.#validateComponentConfig( component );
if ( !res.ok ) return result( [ res.status, `[${ component.id }] Component config is not valid: ${ res.statusText }` ] );
if ( !res.ok ) return result( [ res.status, `[${ component.id }] Component config is not valid. ${ res.statusText }` ] );

// freeze component config
utils.freezeObjectRecursively( component.config );
Expand All @@ -412,7 +412,7 @@ export default class Components {
for ( const component of this ) {
const res = await component.init();

if ( !res.ok ) return result( [ res.status, `[${ component.id }] Failed to init component instance: ${ res.statusText }` ] );
if ( !res.ok ) return result( [ res.status, `[${ component.id }] Failed to init component instance. ${ res.statusText }` ] );
}

return result( 200 );
Expand All @@ -424,7 +424,7 @@ export default class Components {

const res = await component.start();

if ( !res.ok ) return result( [ res.status, `[${ component.id }] Failed to start component instance: ${ res.statusText }` ] );
if ( !res.ok ) return result( [ res.status, `[${ component.id }] Failed to start component instance. ${ res.statusText }` ] );
}

return result( 200 );
Expand All @@ -436,7 +436,7 @@ export default class Components {

const res = await component.afterAppStarted();

if ( !res.ok ) return result( [ res.status, `[${ component.id }] Failed to start component instance after application started: ${ res.statusText }` ] );
if ( !res.ok ) return result( [ res.status, `[${ component.id }] Failed to start component instance after application started. ${ res.statusText }` ] );
}

return result( 200 );
Expand Down Expand Up @@ -577,19 +577,19 @@ export default class Components {

if ( schema ) {
if ( ajv?.getSchema( schema ) && !ajv.validate( schema, config ) ) {
return result( [ 400, `Component "${ component.id }" ${ schema } config is not valid:\n` + ajv.errors ] );
return result( [ 400, `Config schema "${ schema }" errors:\n` + ajv.errors ] );
}
}
else {

// validate env
if ( ajv?.getSchema( "env" ) && !ajv.validate( "env", process.env ) ) {
return result( [ 400, `Component "${ component.id }" env is not valid:\n` + ajv.errors ] );
return result( [ 400, `Eenvironment errors:\n` + ajv.errors ] );
}

// validate config
if ( ajv?.getSchema( "config" ) && !ajv.validate( "config", component.config ) ) {
return result( [ 400, `Component "${ component.id }" config is not valid:\n` + ajv.errors ] );
return result( [ 400, `Cconfig errors:\n` + ajv.errors ] );
}
}

Expand Down

0 comments on commit 219f8eb

Please sign in to comment.