# Diagnostics (DIAG_* reference)

AfterPack द्वारा emit किया जाने वाला हर DIAG_* code, उसे किसने trigger किया, उसे कैसे हल करें, और एक build कौन-से exit codes लौटाती है।

Source: https://www.afterpack.dev/hi/docs/diagnostics

AfterPack कभी भी आपकी माँगी गई protection से कमज़ोर protection ship नहीं करता। जब कुछ अपने-आप हल नहीं हो पाता, तो build एक नामित `DIAG_*` code और एक विशिष्ट समाधान के साथ रुक जाती है।

## Severity के स्तर

AfterPack द्वारा emit किया जाने वाला हर diagnostic ठीक तीन में से एक severity का होता है। कोई `Warning` severity नहीं है।

| Severity | अर्थ | क्या होता है |
|---|---|---|
| **Info** | अपेक्षित व्यवहार: आप इसे पहले ही स्वीकार कर चुके हैं, या engine ने एक सुरक्षित, correctness बनाए रखने वाला fallback लिया। | Build सफल होती है, output लिखा जाता है। |
| **Error** | आपकी बताई गई ज़रूरतें आपकी ओर से किसी बदलाव के बिना पूरी नहीं हो सकतीं (बहुत तंग size cap, parse error, अमान्य key)। | Non-zero exit, **कोई output नहीं लिखा जाता**। |
| **Critical** | Engine का bug। आपकी ओर से कोई कार्रवाई इसे ठीक नहीं करती। | Non-zero exit, कोई output नहीं लिखा जाता, हमेशा। [Report दर्ज करें।](mailto:security@afterpack.dev) |

## Exit codes

`npx afterpack@latest` आठ में से एक code लौटाता है। अपनी scripts सीधे इन्हीं पर लिखें।

| Code | अर्थ |
|---|---|
| `0` | सफलता। हर collected फ़ाइल obfuscate होकर लिखी गई। `--help` और `--version` भी `0` पर exit करते हैं। |
| `1` | विफलता। कोई उपयोगी output नहीं बना, और stderr पर एक message बताता है कि क्या हुआ। |
| `2` | आंशिक। कोटा समाप्त हो चुके build के लिए आरक्षित; आज कोई build इसे नहीं लौटाता। |
| `3` | Size cap। Output आपके सेट किए [`inflation.max`](https://www.afterpack.dev/hi/docs/config#inflation-max) तक पहुँच जाता (`DIAG_SIZE_CAP_REACHED`)। |
| `4` | Pro आवश्यक। कोई [`regions`](https://www.afterpack.dev/hi/docs/config#regions) entry सुरक्षा को program की configuration से ऊपर बढ़ाती है और उसके लिए [`key`](https://www.afterpack.dev/hi/docs/config#key) चाहिए (`DIAG_PRO_DIRECTIVE_REQUIRES_KEY`)। CLI source के directives नहीं पढ़ता, इसलिए इस exit तक केवल `regions` से पहुँचा जा सकता है। |
| `5` | Reflection। [`reflection.allow`](https://www.afterpack.dev/hi/docs/config#reflection-allow) के बिना runtime reflection का पता चला (`DIAG_REFLECTION_NOT_ACKNOWLEDGED`)। |
| `6` | Update ज़रूरी। AfterPack cloud को, या इस `afterpack` को, नया `@afterpack/core` चाहिए। कुछ भी नहीं लिखा गया। |
| `64` | गलत इस्तेमाल। अज्ञात flag या command, गलत रूप वाली value, या दोहराया गया path argument। |

### Build exit 64 क्यों करती है

Usage की समस्याएँ run को शुरू होने से पहले ही रोक देती हैं।

- अज्ञात flag, अज्ञात command, गलत रूप वाली value, या एक से ज़्यादा positional path। Usage line error के साथ फिर से print होती है।

### Build exit 1 क्यों करती है

- कोई `<path>` argument नहीं और कोई build output नहीं मिला (`dist/`, `build/`, `out/`, `.output/`, `.next/`, या `package.json` में नामित bundler की पारंपरिक directory)। AfterPack कभी bundler की अपनी config फ़ाइल नहीं पढ़ता, इसलिए custom output directory इस तरीके से detect नहीं होती।
- Build directory मौजूद नहीं है, या उसमें कोई `.js`/`.mjs`/`.cjs` फ़ाइल नहीं है। खाली build directory build को fail कर देती है। आम कारण है गलत directory की ओर point करना या build से पहले चलाना।
- कोई फ़ाइल पूरी तरह fail हुई, या non-empty input के बावजूद खाली output के साथ लौटी।
- ऐसी फ़ाइल जिसे engine सुरक्षित रूप से obfuscate नहीं कर सकता। Build fail होती है और प्रभावित फ़ाइलों के नाम बताती है। जिस फ़ाइल को बिना छुए ship होना है, उसे अलग करने के लिए [`paths.exclude`](https://www.afterpack.dev/hi/docs/config#paths-exclude) इस्तेमाल करें।
- विफल `verify` या विफल `audit` scan।
- नीचे का कोई भी code जिसकी severity `Error` या `Critical` है, `DIAG_SIZE_CAP_REACHED` (exit `3`), `DIAG_PRO_DIRECTIVE_REQUIRES_KEY` (exit `4`) और `DIAG_REFLECTION_NOT_ACKNOWLEDGED` (exit `5`) को छोड़कर।

### Fail closed, कोई अपवाद नहीं

एक Pro build या तो Pro-level protection ship करती है या ship ही नहीं होती।

*(fail-closed request-flow diagram — see the web page)*

जैसे ही कोई [`key`](https://www.afterpack.dev/hi/docs/config#key), [`AFTERPACK_key`](https://www.afterpack.dev/hi/docs/config#key) या `afterpack.json` से, resolve होती है, build एक cloud build बन जाती है। अगर cloud call किसी भी कारण से fail होता है, तो engine एक error लौटाता है और build `1` पर exit करती है, या `6` पर जब cloud को नया `@afterpack/core` चाहिए। यह local build पर वापस नहीं जाती, और यह बिना obfuscation का output emit नहीं करती। ऐसा कोई flag नहीं है जो बिना obfuscation का output ship करे। Build को रोकने से समस्या वहाँ आती है जहाँ आप उसे देख सकें।

यह contract invocation के रास्ते से नहीं बदलता: `npx afterpack@latest` और bundle बंद होने पर plugin का auto-run बिल्कुल एक जैसा व्यवहार करते हैं।

### CI में exit codes

```bash
npx afterpack@latest dist/ || {
  echo "AfterPack failed: nothing shipped. See the error above."
  exit 1
}
```

Non-zero pipeline को रोक देता है। कारण stderr पर और नीचे के codes में दिखता है।

## पूरा reference

### Engine

| Code | अर्थ |
|---|---|
| `DIAG_TARGET_REACHED` | Info। फ़ाइल का हर हिस्सा माँगी गई [`complexity`](https://www.afterpack.dev/hi/docs/config#complexity) तक पहुँच गया। |
| `DIAG_TARGET_NOT_REACHED` | Engine 0.2.3 से Error, और कोई output नहीं लिखा जाता: फ़ाइल का कोई हिस्सा आपके अनुमति दिए transforms से [`complexity`](https://www.afterpack.dev/hi/docs/config#complexity) target तक नहीं पहुँच सकता, क्योंकि [`transforms.scopeDeepen.enabled`](https://www.afterpack.dev/hi/docs/config#transforms-kind-enabled) `false` है या कोई [region directive](https://www.afterpack.dev/hi/docs/directives#what-you-can-set) उन lines को सीमित करता है। Message फ़ाइल और lines का नाम बताता है। Transform को फिर से चालू करें, उस फ़ाइल या region के लिए `complexity` घटाएँ, या [`paths.exclude`](https://www.afterpack.dev/hi/docs/config#paths-exclude) से फ़ाइल को बाहर रखें। Engine 0.2.2 में यह Info था: build कम गहरा output ship करती थी, और बंद किए गए transform से हुई कमी `DIAG_TARGET_REACHED` के रूप में report हो सकती थी। |
| `DIAG_INFLATION_BUDGET_HIT` | Info। केवल ऐसे non-floor build पर जहाँ सीमित [`inflation.max`](https://www.afterpack.dev/hi/docs/config#inflation-max) सेट है: size बढ़ाने वाला एक stage target तक पहुँचने से पहले उस budget पर रुक गया। Output मान्य है। Engine 0.2.3 से string-constant floor कभी budget के आगे नहीं झुकता, इसलिए floor build पर यह code कभी नहीं आता और इसका मतलब कभी यह नहीं होता कि कोई string literal पढ़ने योग्य रह गया। Engine 0.2.2 में एक स्पष्ट `inflation.max` string encoding को भी बीच में रोक सकता था; अगर आपने इसे सेट किया था, तो engine 0.2.3 से फिर से build करें। |
| `DIAG_SIZE_CAP_REACHED` | Error, exit `3`, और कोई output नहीं लिखा जाता: output आपके सेट किए [`inflation.max`](https://www.afterpack.dev/hi/docs/config#inflation-max) तक पहुँच जाता। Engine 0.2.3 से तैयार फ़ाइल को भी इस सीमा से जाँचा जाता है, message दोनों byte counts बताता है, और सीमा में समाने के लिए string encoding कभी बीच में नहीं रोकी जाती। `inflation.max` बढ़ाएँ, [`complexity`](https://www.afterpack.dev/hi/docs/config#complexity) घटाएँ, या [`paths.exclude`](https://www.afterpack.dev/hi/docs/config#paths-exclude) से फ़ाइल को बाहर रखें। |
| `DIAG_SELF_INTEGRITY_INERT` | Error, engine 0.2.3 से, केवल Pro, और कोई output नहीं लिखा जाता: [`transforms.selfIntegrity.enabled`](https://www.afterpack.dev/hi/docs/config#transforms-kind-enabled) चालू है, लेकिन build में `transforms.crossDependency.enabled` चालू वाला `medium` या उससे ऊपर का कोई code नहीं है जिससे यह जुड़ सके। Preset या किसी region को `medium` तक बढ़ाएँ, `crossDependency` फिर से चालू करें, या `selfIntegrity` बंद करें। Engine 0.2.2 में ऐसी build integrity check के बिना सफल हो जाती थी। |
| `DIAG_PATH_EXCLUDED` | Info। एक फ़ाइल [`paths.exclude`](https://www.afterpack.dev/hi/docs/config#paths-exclude) से मेल खाई और byte-for-byte ship हुई; उसके bytes user-excluded गिने जाते हैं। |
| `DIAG_DYNAMIC_SCOPE_NATIVE` | Info, engine 0.2.3 से। किसी `with` statement या direct `eval` ने अपने आसपास के scopes को वैसा ही छोड़ा जैसा लिखा गया था: उसे घेरने वाले हर scope में, फ़ाइल के top level तक, names अपनी मूल spelling रखते हैं, और `with` body के अंदर globals वैसे ही छोड़े जाते हैं जैसे लिखे गए हैं। फ़ाइल का बाक़ी हिस्सा हमेशा की तरह obfuscate होता है। उन names को सुरक्षित करने के लिए, अगर evaluate होने वाले code को local variables की ज़रूरत नहीं है तो `eval` को indirectly call करें, `(0, eval)(code)`, या जिस code को `eval` या `with` चाहिए उसे एक अलग फ़ाइल में ले जाएँ। देखें [Semantic contract](https://www.afterpack.dev/hi/docs/semantic-contract#what-stays-as-you-wrote-it)। |
| `DIAG_SURVIVING_READABLE_LITERAL` | [`strings.leaks.max`](https://www.afterpack.dev/hi/docs/config#strings-leaks-max) की अनुमति से ज़्यादा readable string literals बचे हैं। [`complexity`](https://www.afterpack.dev/hi/docs/config#complexity) बढ़ाएँ, [`strings.minLength`](https://www.afterpack.dev/hi/docs/config#strings-minLength) घटाएँ, या सीमा बढ़ाएँ। |
| `DIAG_SOURCE_MAP_INTEGRITY` | Info। दिया गया upstream `.map` अपने input के विरुद्ध validation में fail हुआ, इसलिए उस फ़ाइल का source map गिरा दिया जाता है और obfuscated code फिर भी ship होता है। map का न होना हानिरहित है; गलत map ship करना वह नुकसान है जिसे यह टालता है। |
| `DIAG_OUTPUT_UNPARSEABLE` | Error, और engine bug का संकेत। Output को दोबारा parse करना fail हुआ, इसलिए उस फ़ाइल के लिए build fail closed है: कोई code, कोई source map, कोई Protection Map नहीं। |
| `DIAG_PARSE_ERROR` | Error। एक input chunk parse नहीं हुआ। AfterPack सख़्ती से post-build, emitted JavaScript पर चलता है: पहले compile करें, फिर उसे JS output की ओर point करें। |
| `DIAG_CONFIG_PARSE_ERROR` | Error। [Engine config](https://www.afterpack.dev/hi/docs/config) JSON deserialize नहीं हुआ। |
| `DIAG_PRO_DIRECTIVE_REQUIRES_KEY` | Error, exit `4`, और कोई output नहीं लिखा जाता: एक Free build को ऐसा [region directive](https://www.afterpack.dev/hi/docs/directives#free-builds) मिला जो protection को program की configuration से ऊपर बढ़ाता है। एक [`key`](https://www.afterpack.dev/hi/docs/config#key) सेट करें, या directive हटा दें। Engine 0.2.3 से, केवल protection घटाने वाला directive Free पर ignore होता है; engine 0.2.2 उसे भी अस्वीकार करता था। |
| `DIAG_INPUT_TOO_LARGE` | एक अकेला input size की ऊपरी सीमा से बड़ा था। |
| `DIAG_BATCH_TOO_LARGE` | कुल 500 MB से बड़ा batch (413, non-retryable); build fail closed होती है। |
| `DIAG_INPUT_NESTING_EXCEEDS_ENVIRONMENT` | Error। Input उतनी गहराई तक nest होता है जितनी parser सुरक्षित रूप से संभाल नहीं सकता, parsing से पहले ही अनुमानित, 160 levels की सीमा के विरुद्ध। कोई output नहीं। Source की nesting घटाएँ। |
| `DIAG_OUTPUT_NESTING_EXCEEDS_ENVIRONMENT` | Error। Obfuscated output 400 levels से आगे nest हो जाता, जो वह सीमा है जिसे browsers और Workers सुरक्षित रूप से parse कर सकते हैं। कोई output नहीं। उस input के लिए [`complexity`](https://www.afterpack.dev/hi/docs/config#complexity) घटाएँ। |
| `DIAG_ENGINE_BUG_NO_PROGRESS` | Critical। Engine कोई प्रगति नहीं कर सका। यह engine bug है। |
| `DIAG_ENGINE_BUG_NO_APPLICABLE_TRANSFORM` | Critical। फ़ाइल का कोई हिस्सा complexity target से नीचे रह गया, और कोई बंद किया गया transform या region directive इसकी वजह नहीं बताता। यह engine bug है। |
| `DIAG_ENGINE_BUG_PROCESS_THREAD_PANIC` | Critical। एक worker thread panic हुआ। यह engine bug है। |

### Build plugin / CLI

| Code | अर्थ |
|---|---|
| `DIAG_DIRECTIVE_UNKNOWN` | एक `@afterpack` directive ने अपरिचित key का नाम दिया। इसे [उन keys](https://www.afterpack.dev/hi/docs/directives#what-you-can-set) से मिलाएँ जिन्हें एक region override कर सकता है। |
| `DIAG_DIRECTIVE_UNSUPPORTED_FORM` | Marker का रूप place नहीं किया जा सकता (`// @afterpack …` line comment, या `@afterpack:begin/:end` span)। `/* @afterpack … */` block markers इस्तेमाल करें। |
| `DIAG_DIRECTIVE_NOT_IMPLEMENTED` | Directive में लिखी गई एक program-only key (उदाहरण के लिए [`reflection.allow`](https://www.afterpack.dev/hi/docs/config#reflection-allow)), या `skip=false` जैसा अनावश्यक directive। एक region वास्तव में क्या override कर सकता है, इसके लिए [Which keys](https://www.afterpack.dev/hi/docs/directives#what-you-can-set) देखें। |
| `DIAG_DIRECTIVE_SOURCE_UNRESOLVED` | Info। Directive ऐसे module में है जिसकी position build output में map नहीं हो सकी, इसलिए वह लागू नहीं हुआ। चिह्नित code को एक imported module में ले जाएँ। |
| `DIAG_DIRECTIVE_DANGLING_END` | एक [`/* @afterpack end */`](https://www.afterpack.dev/hi/docs/directives#what-you-can-set) जिसके ऊपर कोई खुला block नहीं है। |
| `DIAG_DIRECTIVE_REGION_TO_FILE` | [`identifiers.globals.rename`](https://www.afterpack.dev/hi/docs/config#identifiers-globals-rename) को किसी region तक सीमित नहीं किया जा सकता, इसलिए उसका नाम लेने वाले directive को अनदेखा किया जाता है और रिपोर्ट किया जाता है। |
| `DIAG_DIRECTIVE_COVERAGE_UNVERIFIED` | Directives वाले एक bundled chunk का [कोई decode होने योग्य source map](https://www.afterpack.dev/hi/docs/directives) नहीं था, इसलिए चिह्नित regions उसके bytes में नहीं मिल सके। |
| `DIAG_DIRECTIVE_TARGET_ELIMINATED` | Directives एक chunk के map में मिले, लेकिन शून्य ranges से मेल खाए। चिह्नित code tree-shake हो गया, या coordinates मेल नहीं खाए। |
| `DIAG_ALREADY_OBFUSCATED` | Collected फ़ाइलों में पिछले run का AfterPack का अपना obfuscated output पहले से है, जो content hash के ज़रिए [protection receipt](https://www.afterpack.dev/hi/docs/cli#afterpack-verify-dir) से मिलाया गया। AfterPack output idempotent नहीं है — पहले source से rebuild करें। |
| `DIAG_AFTERPACK_DIR_IN_OUTPUT` | Error, और कुछ भी फिर से नहीं लिखा जाता। build output के अंदर एक `.afterpack/` folder है, जहाँ उसके backups, receipts और Protection Maps build के साथ ship हो जाते। उसे हटाएँ और फिर से build करें। देखें [`.afterpack/` कहाँ रहता है](https://www.afterpack.dev/hi/docs/cli#files)। |
| `DIAG_RECEIPT_UNWRITABLE` | Error, और कुछ भी फिर से नहीं लिखा जाता। [protection receipt](https://www.afterpack.dev/hi/docs/cli#files) `.afterpack/receipts/` में नहीं लिखी जा सकती। उस folder को writable बनाएँ और फिर से build करें। |

### Cloud API

| Code | अर्थ |
|---|---|
| `DIAG_INVALID_KEY` | गायब, गलत रूप वाली, या अज्ञात [`key`](https://www.afterpack.dev/hi/docs/config#key) (401)। [`AFTERPACK_key`](https://www.afterpack.dev/hi/docs/config#key) जाँचें, या [dashboard](https://www.afterpack.dev/hi/docs/dashboard/api-keys) से एक नई key जारी करें। |
| `DIAG_KEY_REVOKED` | API key revoke कर दी गई थी (401)। |
| `DIAG_KEY_EXPIRED` | API key expire हो गई (401)। |
| `DIAG_KEY_OUT_OF_SCOPE` | Request का IP key की अनुमत range से बाहर है (403)। |
| `DIAG_MISSING_IP` | Request में कोई client IP नहीं था (400)। |
| `DIAG_INVALID_MANIFEST` | गलत रूप वाली multipart body, या `batch` manifest part गायब है। |
| `DIAG_FILE_TOO_LARGE` | एक अकेली फ़ाइल प्रति-फ़ाइल byte सीमा से बड़ी थी (413)। उसे बाँटें, या [`paths.exclude`](https://www.afterpack.dev/hi/docs/config#paths-exclude) से बाहर रखें। |
| `DIAG_ENTITLEMENT_LAPSED` | Subscription का भुगतान बकाया है (402); build करते रहने के लिए billing अपडेट करें। |
| `DIAG_QUOTA_EXHAUSTED` | Build का कुल byte [बचे हुए allowance](https://www.afterpack.dev/hi/docs/tiers) से ज़्यादा है, या overage खर्च की सीमा पूरी हो गई है। हर build पर एक बार, किसी भी फ़ाइल के dispatch होने से पहले जाँचा जाता है, इसलिए पहले से protected कुछ भी कमज़ोर नहीं होता। Top up करें, upgrade करें, या सीमा बढ़ाएँ; error में link होता है। |
| `DIAG_RATE_LIMITED` | Rate limit पार हो गई (429); `Retry-After` का पालन करें। |
| `DIAG_RATE_CHECK_UNAVAILABLE` | Rate-limit जाँच ख़ुद fail हुई, इसलिए request fail closed होती है (503); फिर से कोशिश करें। |
| `DIAG_BUILD_DEADLINE` | हर फ़ाइल शुरू होने से पहले wall-clock budget ख़त्म हो गया; अधूरी फ़ाइलों के नाम बताए जाते हैं। |
| `DIAG_ENGINE_FAILURE` | Cloud engine एक फ़ाइल पर fail हुआ। |

### Runtime reflection

AfterPack ये [runtime-reflection](https://www.afterpack.dev/hi/docs/config#reflection-allow) patterns detect करता है: `functionToString`, `nameIntrospection`, `argumentsCallee`, `prototypeChain`, `decoratorMetadata` और `constructorIntrospection`। हर detection के साथ एक code होता है: acknowledge किया गया रूप code में pattern का नाम रखता है, बिना acknowledge वाला रूप एक ही `DIAG_REFLECTION_NOT_ACKNOWLEDGED` है जिसका message उसे नाम देता है।

| Code | अर्थ |
|---|---|
| `DIAG_REFLECTION_nameIntrospection_ACKNOWLEDGED` | Info। Pattern detect हुआ और सुरक्षित रखा गया क्योंकि आपने उसे स्वीकार किया था। हर pattern का एक code; बीच का नाम ऊपर के patterns में से कोई भी है। |
| `DIAG_REFLECTION_NOT_ACKNOWLEDGED` | Error, exit `5`। कोई reflection pattern detect हुआ और स्वीकार **नहीं** किया गया था, इसलिए build ऐसा code ship करने के बजाय रुक जाती है जिसका runtime read टूट जाएगा; message उस pattern का नाम देता है। इसे [`reflection.allow`](https://www.afterpack.dev/hi/docs/config#reflection-allow) से स्वीकार करें, जो `angular` और `nestjs` भी स्वीकार करता है, या [`paths.exclude`](https://www.afterpack.dev/hi/docs/config#paths-exclude) से फ़ाइल को बाहर रखें। |

> **भटके हुए artifacts audit पकड़ता है**
>
> अपने deploy tree में कोई भटका हुआ [`.map`](https://www.afterpack.dev/hi/docs/config#sourceMap-enabled) या बिना obfuscation का sibling ship करना [`npx afterpack@latest audit`](https://www.afterpack.dev/hi/docs/audit) पकड़ता है, build नहीं।
>
> अगर कोई code गायब या गलत है, तो एक issue खोलें: [github.com/afterpack-dev/afterpack/issues](https://github.com/afterpack-dev/afterpack/issues)।

किसी भी build पर डिफ़ॉल्ट summary के बजाय पूरी diagnostic stream के लिए [`--diagnostics.level=all`](https://www.afterpack.dev/hi/docs/config#diagnostics-level) के साथ चलाएँ। Plugin build में यही switch [`diagnostics.level`](https://www.afterpack.dev/hi/docs/config#diagnostics-level) option या [`AFTERPACK_diagnostics_level`](https://www.afterpack.dev/hi/docs/config#diagnostics-level) है।

## आगे

- [CLI reference](https://www.afterpack.dev/hi/docs/cli): ऊपर के codes में उल्लिखित हर flag।
- [Configuration](https://www.afterpack.dev/hi/docs/config): वे config keys जिनका ये codes उल्लेख करते हैं।
- [Semantic contract](https://www.afterpack.dev/hi/docs/semantic-contract): output क्या वैसा ही रखता है, और जान-बूझकर रखे गए कुछ अंतर।
- [Directives](https://www.afterpack.dev/hi/docs/directives): ऊपर के directive codes के पीछे का पूरा `@afterpack` grammar।
- [Best practices](https://www.afterpack.dev/hi/docs/best-practices): वे patterns जो इन diagnostics से शुरू में ही बचाते हैं।
- [Tiers](https://www.afterpack.dev/hi/docs/tiers): क्या Free है और किसके लिए [`key`](https://www.afterpack.dev/hi/docs/config#key) चाहिए।
