• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2024 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, software
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 */
15
16import {
17  ERROR_DESCRIPTION,
18  HvigorErrorInfo,
19  HvigorLogInfo
20} from "./hvigor_error_info";
21
22const DIAGNOSTIC_CODE_MAP: Map<string, Omit<HvigorLogInfo, 'cause' | 'position'>> = new Map([
23  ['28000', { code: '10905128' }],
24  ['28001', { code: '10905239' }],
25  ['28002', { code: '10905238' }],
26  ['28003', { code: '10905127' }],
27  ['28004', { code: '10905353' }],
28  ['28006', { code: '10905237' }],
29  ['28015', { code: '10905236' }],
30]);
31
32export function buildErrorInfoFromDiagnostic(
33  code: number,
34  positionMessage: string,
35  message: string
36): HvigorErrorInfo | undefined {
37  const info: Omit<HvigorLogInfo, 'cause' | 'position'> = DIAGNOSTIC_CODE_MAP.get(code.toString());
38  if (!info || !info.code) {
39    return undefined;
40  }
41  return new HvigorErrorInfo()
42    .setCode(info.code)
43    .setDescription(info.description ?? ERROR_DESCRIPTION)
44    .setCause(message)
45    .setPosition(positionMessage)
46    .setSolutions(info.solutions ?? []);
47}