Skip to content

Commit bac7eb8

Browse files
Fail hard on endpoint compilation errors by default (#5663) (#5665)
(cherry picked from commit 899b8a4) Co-authored-by: Quentin Pradet <quentin.pradet@elastic.co>
1 parent 1a175ec commit bac7eb8

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

compiler/src/steps/validate-model.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,10 @@ const privateNamespaces = ['_internal', 'profiling']
4545
* Any inconsistency is logged as an error.
4646
*
4747
* Missing validations:
48-
* - verify uniqueness of property names in the inheritance chain
4948
* - verify that request parents don't define properties (would they be path/request/body properties?)
5049
* - verify that unions can be distinguished in a JSON stream (otherwise they should be inheritance trees)
5150
*/
5251
export default async function validateModel (apiModel: model.Model, restSpec: Map<string, JsonSpec>, errors: ValidationErrors): Promise<model.Model> {
53-
// Fail hard if the FAIL_HARD env var is defined
54-
const failHard = process.env.FAIL_HARD != null
55-
5652
const initialTypeCount = apiModel.types.length
5753

5854
// Returns the fully-qualified name of a type name
@@ -87,13 +83,20 @@ export default async function validateModel (apiModel: model.Model, restSpec: Ma
8783
function modelError (msg: string): void {
8884
const fullMsg = (context.length === 0) ? msg : context.join(' / ') + ' - ' + msg
8985

86+
let ignored = false
9087
if (currentEndpoint != null) {
91-
errors.addEndpointError(currentEndpoint, currentPart, fullMsg)
88+
ignored = errors.addEndpointError(currentEndpoint, currentPart, fullMsg)
89+
if (!ignored) {
90+
console.error(currentEndpoint, currentPart, fullMsg)
91+
}
9292
} else {
9393
errors.addGeneralError(fullMsg)
94+
console.error(fullMsg)
9495
}
9596

96-
errorCount++
97+
if (!ignored) {
98+
errorCount++
99+
}
97100
}
98101

99102
// ----- Type definition management
@@ -206,8 +209,8 @@ export default async function validateModel (apiModel: model.Model, restSpec: Ma
206209
const danglingTypesCount = initialTypeCount - apiModel.types.length
207210
console.info(`Model validation: ${typesSeen.size} types visited, ${danglingTypesCount} dangling types.`)
208211

209-
if (errorCount > 0 && failHard) {
210-
throw new Error('Model is inconsistent. Check logs for details')
212+
if (errorCount > 0) {
213+
throw new Error('Model is inconsistent.')
211214
}
212215

213216
return apiModel

compiler/src/validation-errors.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ export class ValidationErrors {
3838
}
3939

4040
/** Add some error information relative to an endpoint's request or response */
41-
addEndpointError (endpoint: string, part: 'request' | 'response', message: string): void {
41+
addEndpointError (endpoint: string, part: 'request' | 'response', message: string): boolean {
4242
if (IGNORED_ERRORS.includes(message)) {
43-
return
43+
return true
4444
}
4545

4646
let error = this.endpointErrors[endpoint]
@@ -50,6 +50,7 @@ export class ValidationErrors {
5050
}
5151

5252
error[part].push(message)
53+
return false
5354
}
5455

5556
/** Add a general error, unrelated to an endpoint */

0 commit comments

Comments
 (0)