Made validation messages more descriptive

This commit is contained in:
Eric Nilsson
2020-10-22 12:18:25 +02:00
parent 5cdb613277
commit dab96d0c68
3 changed files with 34 additions and 7 deletions
@@ -14,7 +14,6 @@
* limitations under the License.
*/
import { InputError } from '@backstage/backend-common';
import { Entity, Location, LocationSpec } from '@backstage/catalog-model';
import { v4 as uuidv4 } from 'uuid';
import { Logger } from 'winston';
@@ -81,9 +80,7 @@ export class HigherOrderOperations implements HigherOrderOperation {
const readerOutput = await this.locationReader.read(spec);
if (readerOutput.errors.length) {
const item = readerOutput.errors[0];
throw new InputError(
`Failed to read location ${item.location.type}:${item.location.target}, ${item.error}`,
);
throw item.error;
}
// TODO(freben): At this point, we could detect orphaned entities, by way
@@ -189,7 +189,7 @@ export class LocationReaders implements LocationReader {
);
} catch (e) {
const message = `Processor ${processor.constructor.name} threw an error while preprocessing entity ${kind}:${namespace}/${name} at ${item.location.type} ${item.location.target}, ${e}`;
emit(result.generalError(item.location, message));
emit(result.generalError(item.location, e.message));
logger.warn(message);
return undefined;
}
@@ -207,7 +207,7 @@ export class LocationReaders implements LocationReader {
current = next;
} catch (e) {
const message = `Policy check failed while analyzing entity ${kind}:${namespace}/${name} at ${item.location.type} ${item.location.target}, ${e}`;
emit(result.inputError(item.location, message));
emit(result.inputError(item.location, e.message));
logger.warn(message);
return undefined;
}