# General Translation Platform: 診断
URL: https://generaltranslation.com/ja/docs/platform/core/reference/diagnostics.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: 診断テキストを、ログ出力やレポートを行わずに整形します。createDiagnosticMessage と formatDiagnosticErrorDetails の API リファレンスです。

これらの関数と型は `generaltranslation/diagnostics` からインポートします。いずれも文字列を生成するだけで、ログ出力、例外のレポート、テレメトリの送信、シークレットの秘匿化は行いません。

| エクスポート                                           | 説明                           |
| ------------------------------------------------ | ---------------------------- |
| [`createDiagnosticMessage`](#create-message)     | 診断テキストを組み合わせてメッセージを作成します。    |
| [`DiagnosticMessageInput`](#message-input)       | メッセージのフィールドと任意のコンテキスト。       |
| [`DiagnosticSeverity`](#severity)                | サポートされている重大度ラベル。             |
| [`formatDiagnosticErrorDetails`](#error-details) | unknown 型のエラーを任意のテキストに変換します。 |

## `createDiagnosticMessage` [#create-message]

**シグネチャ** `(input: DiagnosticMessageInput) => string`

指定されたフィールドを、「何が起きたかとその理由」「安心させるメッセージ」「修正方法と回避策」「詳細」「ドキュメントの URL」の順に結合します。各文の前後の空白をトリムし、必要に応じて句読点を補います。任意の source と severity はプレフィックスとして使用されます。また、小文字で始まる `wayOut` は、修正方法の文に続けて 1 文にまとめることができます。

```ts
import { createDiagnosticMessage } from 'generaltranslation/diagnostics';

const message = createDiagnosticMessage({
  source: 'Importer',
  severity: 'Warning',
  whatHappened: 'The file was skipped',
  fix: 'Choose a supported format',
});
// 文字列を返すだけで、自動ではログに出力されません。
console.log(message);
```

## `DiagnosticMessageInput` [#message-input]

**型** object · メッセージフォーマッタへの**必須**入力

| フィールド          | 説明                         | 型                    | 任意  | デフォルト |
| -------------- | -------------------------- | -------------------- | --- | ----- |
| `whatHappened` | 主な説明。                      | `string`             | いいえ | —     |
| `source`       | 呼び出し元を識別するプレフィックス。         | `string`             | はい  | —     |
| `severity`     | プレフィックスとして付くラベル。           | `DiagnosticSeverity` | はい  | —     |
| `reassurance`  | 引き続き安全なもの、または影響を受けないもの。    | `string`             | はい  | —     |
| `why`          | 原因。主な説明に連結されます。            | `string`             | はい  | —     |
| `fix`          | 推奨される対処方法。                 | `string`             | はい  | —     |
| `wayOut`       | 代替となる対処方法。                 | `string`             | はい  | —     |
| `details`      | 追加の詳細。配列はカンマ区切りで連結されます。    | `string \| string[]` | はい  | —     |
| `docsUrl`      | メッセージの末尾に追加されるドキュメントの URL。 | `string`             | はい  | —     |

必須なのは `whatHappened` のみです。省略した任意フィールドからはテキストが出力されません。各節は、文中に置いたときの大文字・小文字のまま指定してください。フォーマッタは秘匿化を一切行わないため、`details` などのフィールドにシークレットを含めないでください。

```ts
import type { DiagnosticMessageInput } from 'generaltranslation/diagnostics';

const input: DiagnosticMessageInput = { whatHappened: 'No files matched' };
```

## `DiagnosticSeverity` [#severity]

**型** `'Error' | 'Warning'`

これは任意で付与されるテキストラベルを制御するもので、ログレベルや例外の挙動には影響しません。severity を省略した場合、severity のプレフィックスは付加されません。

```ts
import type { DiagnosticSeverity } from 'generaltranslation/diagnostics';

const severity: DiagnosticSeverity = 'Warning';
```

## `formatDiagnosticErrorDetails` [#error-details]

**シグネチャ** `(error: unknown) => string | undefined`

`null` または `undefined` の場合は `undefined` を返し、それ以外の場合は `String(error)` を返します。構造化されたエラーのフィールドを抽出したり、その内容を秘匿化したりはしません。

```ts
import { formatDiagnosticErrorDetails } from 'generaltranslation/diagnostics';

console.log(formatDiagnosticErrorDetails(new Error('Invalid file'))); // Error: Invalid file
console.log(formatDiagnosticErrorDetails(null)); // undefined
```

## Sitemap

See the full [sitemap](https://generaltranslation.com/sitemap.md) for all pages.
