1 | /*
|
2 | * Licensed under the Apache License, Version 2.0 (the "License");
|
3 | * you may not use this file except in compliance with the License.
|
4 | * You may obtain a copy of the License at
|
5 | *
|
6 | * http://www.apache.org/licenses/LICENSE-2.0
|
7 | *
|
8 | * Unless required by applicable law or agreed to in writing, software
|
9 | * distributed under the License is distributed on an "AS IS" BASIS,
|
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
11 | * See the License for the specific language governing permissions and
|
12 | * limitations under the License.
|
13 | */
|
14 |
|
15 | ;
|
16 |
|
17 | const BaseFileException = require('../basefileexception');
|
18 |
|
19 | /**
|
20 | * Exception throws when a composer file is semantically invalid
|
21 | * @extends BaseFileException
|
22 | * @see See {@link BaseFileException}
|
23 | * @class
|
24 | * @memberof module:concerto-core
|
25 | * @private
|
26 | */
|
27 | class IllegalModelException extends BaseFileException {
|
28 |
|
29 | /**
|
30 | * Create an IllegalModelException.
|
31 | * @param {String} message - the message for the exception
|
32 | * @param {ModelFile} [modelFile] - the optional modelfile associated with the exception
|
33 | * @param {Object} [fileLocation] - location details of the error within the model file.
|
34 | * @param {number} fileLocation.start.line - start line of the error location.
|
35 | * @param {number} fileLocation.start.column - start column of the error location.
|
36 | * @param {number} fileLocation.end.line - end line of the error location.
|
37 | * @param {number} fileLocation.end.column - end column of the error location.
|
38 | * @param {String} component - the optional component which throws this error
|
39 | */
|
40 | constructor(message, modelFile, fileLocation, component) {
|
41 |
|
42 | let messageSuffix = '';
|
43 | let fileName = null;
|
44 | if(modelFile && modelFile.getName()) {
|
45 | fileName = modelFile.getName();
|
46 | messageSuffix = 'File \'' + fileName + '\': ' ;
|
47 | }
|
48 |
|
49 | if(fileLocation) {
|
50 | messageSuffix = messageSuffix + 'line ' + fileLocation.start.line + ' column ' +
|
51 | fileLocation.start.column + ', to line ' + fileLocation.end.line + ' column ' +
|
52 | fileLocation.end.column + '. ';
|
53 | }
|
54 |
|
55 | // First character to be uppercase
|
56 | messageSuffix = messageSuffix.charAt(0).toUpperCase() + messageSuffix.slice(1);
|
57 |
|
58 | super(message, fileLocation, message + ' ' + messageSuffix, fileName, component);
|
59 | }
|
60 | }
|
61 |
|
62 | module.exports = IllegalModelException;
|