2017-01-26 17:07:37 -08:00
/ * *
* @license
* Copyright Google Inc . All Rights Reserved .
*
* Use of this source code is governed by an MIT - style license that can be
* found in the LICENSE file at https : //angular.io/license
* /
2017-01-27 13:19:00 -08:00
import { ERROR_DEBUG_CONTEXT , ERROR_ORIGINAL_ERROR , getDebugContext } from '../errors' ;
2017-02-03 15:20:50 -08:00
import { DebugContext , ViewState } from './types' ;
2017-01-26 17:07:37 -08:00
export function expressionChangedAfterItHasBeenCheckedError (
2017-01-27 13:19:00 -08:00
context : DebugContext , oldValue : any , currValue : any , isFirstCheck : boolean ) : Error {
2017-01-26 17:07:37 -08:00
let msg =
2017-02-03 15:20:50 -08:00
` ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: ' ${ oldValue } '. Current value: ' ${ currValue } '. ` ;
2017-01-26 17:07:37 -08:00
if ( isFirstCheck ) {
msg +=
` It seems like the view has been created after its parent and its children have been dirty checked. ` +
` Has it been created in a change detection hook ? ` ;
}
2017-01-31 14:52:01 -08:00
return viewDebugError ( msg , context ) ;
2017-01-26 17:07:37 -08:00
}
2017-01-27 13:19:00 -08:00
export function viewWrappedDebugError ( originalError : any , context : DebugContext ) : Error {
const err = viewDebugError ( originalError . message , context ) ;
( err as any ) [ ERROR_ORIGINAL_ERROR ] = originalError ;
2017-01-26 17:07:37 -08:00
return err ;
}
2017-01-27 13:19:00 -08:00
export function viewDebugError ( msg : string , context : DebugContext ) : Error {
const err = new Error ( msg ) ;
( err as any ) [ ERROR_DEBUG_CONTEXT ] = context ;
2017-01-26 17:07:37 -08:00
err . stack = context . source ;
return err ;
}
2017-01-27 13:19:00 -08:00
export function isViewDebugError ( err : Error ) : boolean {
return ! ! getDebugContext ( err ) ;
2017-01-26 17:07:37 -08:00
}
2017-01-31 14:52:01 -08:00
2017-02-03 15:20:50 -08:00
export function viewDestroyedError ( action : string ) : Error {
return new Error ( ` ViewDestroyedError: Attempt to use a destroyed view: ${ action } ` ) ;
2017-01-31 14:52:01 -08:00
}