Parse and validate AT Protocol Lexicons with DTO generation for Laravel
1<?php
2
3namespace SocialDept\AtpSchema\Exceptions;
4
5class GenerationException extends SchemaException
6{
7 /**
8 * Create exception for generation failure.
9 */
10 public static function failed(string $nsid, string $reason): self
11 {
12 return static::withContext(
13 "Failed to generate Data class for {$nsid}: {$reason}",
14 ['nsid' => $nsid, 'reason' => $reason]
15 );
16 }
17
18 /**
19 * Create exception for file write failure.
20 */
21 public static function fileWriteFailed(string $path, string $error): self
22 {
23 return static::withContext(
24 "Failed to write generated file to {$path}: {$error}",
25 ['path' => $path, 'error' => $error]
26 );
27 }
28
29 /**
30 * Create exception for unsupported feature.
31 */
32 public static function unsupportedFeature(string $nsid, string $feature): self
33 {
34 return static::withContext(
35 "Unsupported feature in schema {$nsid}: {$feature}",
36 ['nsid' => $nsid, 'feature' => $feature]
37 );
38 }
39
40 /**
41 * Create exception for template not found.
42 */
43 public static function templateNotFound(string $templateName): self
44 {
45 return static::withContext(
46 "Template not found: {$templateName}",
47 ['template' => $templateName]
48 );
49 }
50
51 /**
52 * Create exception for file already exists.
53 */
54 public static function fileExists(string $path): self
55 {
56 return static::withContext(
57 "File already exists: {$path}",
58 ['path' => $path]
59 );
60 }
61
62 /**
63 * Create exception for directory not found.
64 */
65 public static function directoryNotFound(string $directory): self
66 {
67 return static::withContext(
68 "Directory not found: {$directory}",
69 ['directory' => $directory]
70 );
71 }
72
73 /**
74 * Create exception for cannot create directory.
75 */
76 public static function cannotCreateDirectory(string $directory): self
77 {
78 return static::withContext(
79 "Cannot create directory: {$directory}",
80 ['directory' => $directory]
81 );
82 }
83
84 /**
85 * Create exception for cannot write file.
86 */
87 public static function cannotWriteFile(string $path): self
88 {
89 return static::withContext(
90 "Cannot write file: {$path}",
91 ['path' => $path]
92 );
93 }
94
95 /**
96 * Create exception for cannot delete file.
97 */
98 public static function cannotDeleteFile(string $path): self
99 {
100 return static::withContext(
101 "Cannot delete file: {$path}",
102 ['path' => $path]
103 );
104 }
105
106 /**
107 * Create exception for file not found.
108 */
109 public static function fileNotFound(string $path): self
110 {
111 return static::withContext(
112 "File not found: {$path}",
113 ['path' => $path]
114 );
115 }
116
117 /**
118 * Create exception for cannot read file.
119 */
120 public static function cannotReadFile(string $path): self
121 {
122 return static::withContext(
123 "Cannot read file: {$path}",
124 ['path' => $path]
125 );
126 }
127}