• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, softwarecheck{  }
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15import ts from 'typescript';
16import { ApiResultSimpleInfo, ApiResultInfo } from '../../../typedef/checker/result_type';
17
18export class AddErrorLogs {
19  /**
20   * 按照格式生成错误信息
21   * @param { number } id -error message id
22   * @param { number } level -error level
23   * @param { string } filePath -error message file path
24   * @param { string } location -error message location
25   * @param { string } errorType -error message wrong type
26   * @param { string } apiType -error message log type
27   * @param { number } version -error message version
28   * @param { string } apiName -error message api name
29   * @param { string } apiFullText -error message api text
30   * @param { string } message -error infomation
31   * @param { ApiResultSimpleInfo[] }  checkErrorInfos -array for storing error information
32   */
33  static addAPICheckErrorLogs(
34    id: number,
35    level: number,
36    filePath: string,
37    pos: ts.LineAndCharacter,
38    errorType: string,
39    apiType: string,
40    version: number,
41    apiName: string,
42    apiFullText: string,
43    message: string,
44    checkErrorInfos: ApiResultSimpleInfo[],
45    checkErrorAllInfos: ApiResultInfo[]
46  ): void {
47    const location = `${filePath}(line:${pos.line},character:${pos.character})`;
48    const errorMessage: string = `API check error of [${errorType}]: ${message}`;
49    const apiChecktSimpleErrorLog: ApiResultSimpleInfo = new ApiResultSimpleInfo();
50    apiChecktSimpleErrorLog
51      .setID(id)
52      .setLevel(level)
53      .setLocation(location)
54      .setFilePath(filePath)
55      .setMessage(errorMessage);
56
57    const apiCheckErrorLog: ApiResultInfo = new ApiResultInfo();
58    apiCheckErrorLog
59      .setErrorType(errorType)
60      .setLocation(location)
61      .setApiType(apiType)
62      .setMessage(errorMessage)
63      .setVersion(version)
64      .setLevel(level)
65      .setApiName(apiName)
66      .setApiFullText(apiFullText)
67      .setBaseName(filePath.substring(filePath.lastIndexOf('/') + 1, filePath.length));
68    checkErrorInfos.push(apiChecktSimpleErrorLog);
69    checkErrorAllInfos.push(apiCheckErrorLog);
70  }
71}
72