@bytefaceinc/web-lang 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,863 @@
1
+ # WEB Error Handling And Troubleshooting
2
+
3
+ This document explains how to diagnose and fix common WEB compiler and CLI errors.
4
+
5
+ Use it when:
6
+
7
+ - a `.web` file fails to compile
8
+ - the compiler message is technically correct but you want the practical fix
9
+ - you are unsure whether something belongs in DOM scope, CSS scope, `define`, `::attrs`, `::head`, or `::script`
10
+ - the CLI resolves a target differently than you expected
11
+
12
+ ## 1. How To Read Modern Compiler Errors
13
+
14
+ The compiler now tries to explain errors in a developer-friendly format.
15
+
16
+ A typical error includes:
17
+
18
+ - the original failure message
19
+ - `Source:` with file name and `line:column`
20
+ - `Phase:` such as `lexing`, `parsing`, `semantic analysis`, `HTML preparation`, or `CSS preparation`
21
+ - `Violation:` which explains the rule that was broken
22
+ - `Found:` which shows the token or character that caused the failure
23
+ - `How to fix:` with the concrete correction to make
24
+ - `Example:` with a valid pattern
25
+ - `Context:` with a code frame and caret
26
+
27
+ Example:
28
+
29
+ ```text
30
+ Expected ";" after assignment (line 8, column 3)
31
+ Source: home.web:8:3
32
+ Phase: parsing
33
+ Violation: WEB terminates declarations, assignments, and attribute entries with a semicolon.
34
+ Found: token IDENTIFIER "pageTitle"
35
+ How to fix: Add `;` at the end of the current statement before starting the next statement or closing the block.
36
+ Example: heroTitle.textContent = "Hello";
37
+ Context:
38
+ 7 | pageTitle.textContent = "Missing semicolon"
39
+ > 8 | pageTitle.color = "#223344";
40
+ | ^
41
+ 9 | }
42
+ ```
43
+
44
+ ## 2. Fast Triage Checklist
45
+
46
+ When a file fails, check these first:
47
+
48
+ 1. Did every assignment end with `;`?
49
+ 2. Did every `{` get a matching `}`?
50
+ 3. Did you put strings, URLs, and hex colors in quotes?
51
+ 4. Did you keep variables, type declarations, and `extends` declarations inside one top-level `define { ... }` block?
52
+ 5. Did you put only HTML attributes inside `::attrs`?
53
+ 6. Did you keep `::head` and `::script` at the top level?
54
+ 7. Did you use only valid value types: string, template literal, number, percentage, identifier, variable, or `js` literal?
55
+ 8. If using the CLI, did the target actually resolve to one or more `.web` files?
56
+
57
+ ## 3. Common Syntax Errors
58
+
59
+ ### Missing semicolon
60
+
61
+ Symptom:
62
+
63
+ - `Expected ";" after assignment`
64
+ - `Expected ";" after declaration`
65
+ - `Expected ";" after variable declaration`
66
+
67
+ Why it happens:
68
+
69
+ - WEB statements are terminated with semicolons.
70
+
71
+ Wrong:
72
+
73
+ ```web
74
+ heroTitle.textContent = "Hello"
75
+ heroTitle.color = "#223344";
76
+ ```
77
+
78
+ Right:
79
+
80
+ ```web
81
+ heroTitle.textContent = "Hello";
82
+ heroTitle.color = "#223344";
83
+ ```
84
+
85
+ ### Missing `=`
86
+
87
+ Symptom:
88
+
89
+ - `Expected "=" after ...`
90
+
91
+ Why it happens:
92
+
93
+ - Assignments in WEB use `=`, not `:`.
94
+
95
+ Wrong:
96
+
97
+ ```web
98
+ heroTitle.color: "#223344";
99
+ ```
100
+
101
+ Right:
102
+
103
+ ```web
104
+ heroTitle.color = "#223344";
105
+ ```
106
+
107
+ ### Missing `{` or `}`
108
+
109
+ Symptom:
110
+
111
+ - `Expected "{" after ...`
112
+ - `Expected "}" after ...`
113
+ - `Unterminated ...`
114
+
115
+ Why it happens:
116
+
117
+ - Block headers must open with `{`
118
+ - every block must close with `}`
119
+
120
+ Wrong:
121
+
122
+ ```web
123
+ heroSection
124
+ padding = "2rem";
125
+ ```
126
+
127
+ Right:
128
+
129
+ ```web
130
+ heroSection {
131
+ padding = "2rem";
132
+ }
133
+ ```
134
+
135
+ ### Unquoted values that need punctuation or spaces
136
+
137
+ Symptom:
138
+
139
+ - `Unexpected character "#"`
140
+ - `Unexpected value token ...`
141
+
142
+ Why it happens:
143
+
144
+ - WEB accepts simple identifier values like `Hello`
145
+ - but values containing punctuation or spaces, such as `#223344`, `/docs`, or `Hello world`, must be quoted
146
+ - quoting URLs, prose, and hex colors is the safest default
147
+
148
+ Wrong:
149
+
150
+ ```web
151
+ heroLink.href = /docs;
152
+ heroTitle.color = #223344;
153
+ heroTitle.textContent = Hello world;
154
+ ```
155
+
156
+ Right:
157
+
158
+ ```web
159
+ heroLink.href = "/docs";
160
+ heroTitle.color = "#223344";
161
+ heroTitle.textContent = "Hello world";
162
+ ```
163
+
164
+ ### Broken dot notation
165
+
166
+ Symptom:
167
+
168
+ - `Expected an identifier after "."`
169
+
170
+ Why it happens:
171
+
172
+ - every `.` in a path must be followed by a normal identifier
173
+
174
+ Wrong:
175
+
176
+ ```web
177
+ pageMain..heroTitle.textContent = "Hello";
178
+ ```
179
+
180
+ Right:
181
+
182
+ ```web
183
+ pageMain.heroTitle.textContent = "Hello";
184
+ ```
185
+
186
+ ### Unterminated strings or literals
187
+
188
+ Symptom:
189
+
190
+ - `Unterminated string literal`
191
+ - `Unterminated template literal`
192
+ - `Unterminated JavaScript inject literal`
193
+
194
+ Why it happens:
195
+
196
+ - the closing quote or backtick is missing
197
+
198
+ Wrong:
199
+
200
+ ```web
201
+ heroTitle.textContent = "Hello;
202
+ ```
203
+
204
+ Right:
205
+
206
+ ```web
207
+ heroTitle.textContent = "Hello";
208
+ ```
209
+
210
+ Wrong:
211
+
212
+ ```web
213
+ heroCopy.innerHTML = js`return "<strong>Hello</strong>";
214
+ ```
215
+
216
+ Right:
217
+
218
+ ```web
219
+ heroCopy.innerHTML = js`return "<strong>Hello</strong>";`;
220
+ ```
221
+
222
+ ## 4. Block Placement Errors
223
+
224
+ ### `define { ... }` in the wrong place
225
+
226
+ Symptom:
227
+
228
+ - `The define { ... } block must appear once at the top of the file before any rules.`
229
+ - `Only one top-level define { ... } block is allowed.`
230
+
231
+ Why it happens:
232
+
233
+ - WEB allows only one top-level `define` block
234
+ - it must come before normal element rules
235
+
236
+ Wrong:
237
+
238
+ ```web
239
+ pageMain.padding = "2rem";
240
+
241
+ define {
242
+ @gap = "1rem";
243
+ }
244
+ ```
245
+
246
+ Right:
247
+
248
+ ```web
249
+ define {
250
+ @gap = "1rem";
251
+ }
252
+
253
+ pageMain.padding = @gap;
254
+ ```
255
+
256
+ ### Variables, type declarations, or `extends` outside `define`
257
+
258
+ Symptom:
259
+
260
+ - `Variables must be declared inside a top-level define { ... } block before any rules.`
261
+ - `Type declarations must be declared inside a top-level define { ... } block before any rules.`
262
+ - `Style inheritance must be declared inside a top-level define { ... } block before any rules.`
263
+
264
+ Why it happens:
265
+
266
+ - these declarations are only legal inside the single top-level `define` block
267
+
268
+ Wrong:
269
+
270
+ ```web
271
+ @gap = "1rem";
272
+ Button primaryButton;
273
+ primaryButton extends buttonBase;
274
+ ```
275
+
276
+ Right:
277
+
278
+ ```web
279
+ define {
280
+ @gap = "1rem";
281
+ Button primaryButton;
282
+ primaryButton extends buttonBase;
283
+ }
284
+ ```
285
+
286
+ ### `::attrs` used in the wrong scope
287
+
288
+ Symptom:
289
+
290
+ - `::attrs blocks must be nested directly inside an element scope.`
291
+ - `::attrs blocks only support direct HTML attribute assignments like href = "/docs";`
292
+
293
+ Why it happens:
294
+
295
+ - `::attrs` is only for HTML attributes
296
+ - it must live inside a normal DOM element block
297
+ - it cannot contain nested blocks, CSS properties, or content properties
298
+
299
+ Wrong:
300
+
301
+ ```web
302
+ styles {
303
+ card {
304
+ ::attrs {
305
+ href = "/docs";
306
+ }
307
+ }
308
+ }
309
+ ```
310
+
311
+ Wrong:
312
+
313
+ ```web
314
+ docsLink {
315
+ ::attrs {
316
+ color = "#223344";
317
+ textContent = "Docs";
318
+ }
319
+ }
320
+ ```
321
+
322
+ Right:
323
+
324
+ ```web
325
+ docsLink {
326
+ textContent = "Docs";
327
+
328
+ ::attrs {
329
+ href = "/docs";
330
+ ariaLabel = "Open docs";
331
+ }
332
+ }
333
+ ```
334
+
335
+ ### `::head` and `::script` nested inside element scopes
336
+
337
+ Symptom:
338
+
339
+ - `::head blocks must be declared at the top level outside element, style, pseudo, and media scopes.`
340
+ - `::script blocks must be declared at the top level outside element, style, pseudo, and media scopes.`
341
+
342
+ Why it happens:
343
+
344
+ - these blocks describe document-level output, not a single DOM node
345
+
346
+ Wrong:
347
+
348
+ ```web
349
+ pageMain {
350
+ ::head {
351
+ meta {
352
+ name = "description";
353
+ content = "Demo";
354
+ }
355
+ }
356
+ }
357
+ ```
358
+
359
+ Right:
360
+
361
+ ```web
362
+ ::head {
363
+ meta {
364
+ name = "description";
365
+ content = "Demo";
366
+ }
367
+ }
368
+ ```
369
+
370
+ ### Misusing `styles`, `::pseudo`, or `::media`
371
+
372
+ Symptom:
373
+
374
+ - `styles blocks only support CSS properties and raw assignments`
375
+ - `Pseudo blocks and media queries only support CSS properties and raw assignments`
376
+
377
+ Why it happens:
378
+
379
+ - CSS scopes are for CSS only
380
+ - they do not accept `textContent`, `innerHTML`, or HTML attributes
381
+
382
+ Wrong:
383
+
384
+ ```web
385
+ card {
386
+ styles {
387
+ title {
388
+ textContent = "Hello";
389
+ }
390
+ }
391
+ }
392
+ ```
393
+
394
+ Right:
395
+
396
+ ```web
397
+ card {
398
+ title {
399
+ textContent = "Hello";
400
+ }
401
+
402
+ styles {
403
+ title {
404
+ color = "#223344";
405
+ }
406
+ }
407
+ }
408
+ ```
409
+
410
+ ### Global style blocks in the wrong place
411
+
412
+ Symptom:
413
+
414
+ - `Global style blocks using "*" or "html" must be declared at the top level or inside a top-level ::media block without a parent selector.`
415
+
416
+ Why it happens:
417
+
418
+ - `html { ... }` and `* { ... }` are reserved for global CSS
419
+ - they are not element blocks
420
+
421
+ Wrong:
422
+
423
+ ```web
424
+ pageMain {
425
+ html {
426
+ backgroundColor = "#101522";
427
+ }
428
+ }
429
+ ```
430
+
431
+ Right:
432
+
433
+ ```web
434
+ html {
435
+ backgroundColor = "#101522";
436
+ }
437
+ ```
438
+
439
+ ## 5. Common Semantic Errors And Misconceptions
440
+
441
+ ### Misconception: `extends` creates DOM inheritance
442
+
443
+ Reality:
444
+
445
+ - `derivedName extends baseName;` only affects CSS inheritance in the compiler
446
+ - it does not create parent-child HTML structure
447
+
448
+ Wrong assumption:
449
+
450
+ ```web
451
+ define {
452
+ primaryButton extends buttonBase;
453
+ }
454
+ ```
455
+
456
+ This does not create a nested node or shared DOM structure.
457
+
458
+ Use real nesting for DOM structure:
459
+
460
+ ```web
461
+ pageMain {
462
+ primaryButton {
463
+ textContent = "Launch";
464
+ }
465
+ }
466
+ ```
467
+
468
+ ### Misconception: `styles { ... }` creates HTML nodes
469
+
470
+ Reality:
471
+
472
+ - `styles { ... }` only contributes CSS
473
+ - if a node exists only inside `styles`, it does not create HTML output
474
+
475
+ If you want HTML, define the node in normal DOM scope:
476
+
477
+ ```web
478
+ card {
479
+ title {
480
+ textContent = "Hello";
481
+ }
482
+ }
483
+ ```
484
+
485
+ ### Unknown variable
486
+
487
+ Symptom:
488
+
489
+ - `Unknown variable "@accent"`
490
+
491
+ Why it happens:
492
+
493
+ - the variable was never declared
494
+ - the variable name was misspelled
495
+
496
+ Fix:
497
+
498
+ - declare it inside `define`
499
+ - use the exact same name everywhere
500
+
501
+ Right:
502
+
503
+ ```web
504
+ define {
505
+ @accent = "#94a7ca";
506
+ }
507
+
508
+ heroTitle.color = @accent;
509
+ ```
510
+
511
+ ### Circular references
512
+
513
+ Symptom:
514
+
515
+ - `Circular variable reference involving "..."`
516
+ - `Circular type inheritance involving "..."`
517
+ - `Circular style inheritance involving "..."`
518
+
519
+ Why it happens:
520
+
521
+ - the compiler detected a loop
522
+
523
+ Fix:
524
+
525
+ - break the cycle so the chain resolves in one direction only
526
+
527
+ Wrong:
528
+
529
+ ```web
530
+ define {
531
+ @a = @b;
532
+ @b = @a;
533
+ }
534
+ ```
535
+
536
+ Right:
537
+
538
+ ```web
539
+ define {
540
+ @a = "#94a7ca";
541
+ @b = @a;
542
+ }
543
+ ```
544
+
545
+ ### Void elements cannot contain content
546
+
547
+ Symptom:
548
+
549
+ - `Void element <...> cannot contain content or children for "..."`
550
+
551
+ Why it happens:
552
+
553
+ - some HTML tags cannot contain children or text
554
+ - examples include `img`, `input`, `meta`, and `link`
555
+
556
+ Fix:
557
+
558
+ - move text or children to a non-void element
559
+ - keep the void element for attributes only
560
+
561
+ Wrong:
562
+
563
+ ```web
564
+ heroImage {
565
+ textContent = "Preview";
566
+ }
567
+ ```
568
+
569
+ Right:
570
+
571
+ ```web
572
+ heroImage {
573
+ ::attrs {
574
+ src = "/hero.png";
575
+ alt = "Preview";
576
+ }
577
+ }
578
+ ```
579
+
580
+ ### Misconception: `js\`...\`` runs in the browser
581
+
582
+ Reality:
583
+
584
+ - `js\`...\`` runs at compile time in Node
585
+ - it does not create browser-side runtime logic by itself
586
+
587
+ Use `::script` when you need emitted browser JavaScript:
588
+
589
+ ```web
590
+ ::script {
591
+ src = "/assets/app.js";
592
+ }
593
+ ```
594
+
595
+ ## 6. Keyframes And Animation Mistakes
596
+
597
+ ### Invalid keyframe stage
598
+
599
+ Symptom:
600
+
601
+ - `Expected a keyframe stage such as "from", "to", or "50%"`
602
+
603
+ Why it happens:
604
+
605
+ - only `from`, `to`, or percentage stages are valid
606
+
607
+ Wrong:
608
+
609
+ ```web
610
+ ::keyframes fadeIn {
611
+ start {
612
+ opacity = 0;
613
+ }
614
+ }
615
+ ```
616
+
617
+ Right:
618
+
619
+ ```web
620
+ ::keyframes fadeIn {
621
+ from {
622
+ opacity = 0;
623
+ }
624
+
625
+ to {
626
+ opacity = 1;
627
+ }
628
+ }
629
+ ```
630
+
631
+ ## 7. Raw CSS Misunderstandings
632
+
633
+ ### Broken `raw` CSS block
634
+
635
+ Symptom:
636
+
637
+ - `Unterminated CSS block in raw template literal`
638
+ - `Unterminated quoted text in raw CSS`
639
+ - `Unterminated CSS block comment in raw template literal`
640
+
641
+ Why it happens:
642
+
643
+ - the CSS inside the template literal is malformed
644
+
645
+ Fix:
646
+
647
+ - treat the inside of `raw = \`...\`;` as real CSS syntax
648
+ - make sure braces, quotes, and comments are balanced
649
+
650
+ Right:
651
+
652
+ ```web
653
+ primaryButton {
654
+ raw = `
655
+ transition: transform 0.2s ease;
656
+ &:hover { transform: translateY(-2px); }
657
+ `;
658
+ }
659
+ ```
660
+
661
+ ## 8. CLI Errors And Common Misconceptions
662
+
663
+ ### `web .` is not recursive
664
+
665
+ Common misconception:
666
+
667
+ - `web .` will compile every `.web` file in every nested folder
668
+
669
+ Reality:
670
+
671
+ - `web .` compiles only direct `.web` files in the current directory
672
+
673
+ If you want nested files, target them explicitly:
674
+
675
+ ```bash
676
+ web ./code/*
677
+ ```
678
+
679
+ ### Bare names only resolve to `name.web`
680
+
681
+ Common misconception:
682
+
683
+ - `web home` might resolve `home.txt`, `home.html`, or a directory
684
+
685
+ Reality:
686
+
687
+ - bare-name convenience only checks for `home.web`
688
+
689
+ ### `web init` will not overwrite existing scaffold files
690
+
691
+ Common misconception:
692
+
693
+ - `web init` should replace whatever `index.web`, `index.html`, `index.css`, or `web-lang-agents.md` already exist in the directory
694
+
695
+ Reality:
696
+
697
+ - the init command refuses to overwrite those scaffold files
698
+ - this protects existing work from being replaced by the starter template
699
+
700
+ Fix:
701
+
702
+ - run `web init` in a clean directory
703
+ - or move/remove the conflicting files before you try again
704
+
705
+ ### `web init` expects a directory target
706
+
707
+ Common misconception:
708
+
709
+ - `web init website.txt`
710
+ - `web init existing-file`
711
+
712
+ Reality:
713
+
714
+ - the init command accepts one directory target, not a file target
715
+ - if the path already exists and is a file, the CLI stops before scaffolding
716
+
717
+ Fix:
718
+
719
+ - pass `.` for the current directory
720
+ - pass a directory path like `website` or `./projects/website`
721
+ - rename or remove the conflicting file if you meant to use that path as a directory
722
+
723
+ ### `web watch` only accepts one resolved `.web` source
724
+
725
+ Common misconception:
726
+
727
+ - `web watch .`
728
+ - `web watch ./pages/*`
729
+ - `web watch home.web about.web`
730
+
731
+ Reality:
732
+
733
+ - the watch command currently watches one resolved `.web` source at a time
734
+
735
+ Fix:
736
+
737
+ - point the watch command at a single file
738
+ - use `web home.web` or `web ./pages/*` for one-off multi-file compiles
739
+ - start a second watch session in another terminal if you need to watch a different file
740
+
741
+ ### `web-lang-screenshots` is created in the current working directory
742
+
743
+ Common misconception:
744
+
745
+ - screenshots are written next to the source file
746
+
747
+ Reality:
748
+
749
+ - screenshots are written into `./web-lang-screenshots` rooted at the directory where you ran the CLI
750
+
751
+ Fix:
752
+
753
+ - look for screenshots in the current working directory first
754
+ - if the source file is inside the current working directory, check for preserved subfolders inside `web-lang-screenshots`
755
+ - remember that filenames also include readable timestamps
756
+
757
+ ### `web watch` stopped because there was no recent activity
758
+
759
+ Common misconception:
760
+
761
+ - the watch session should stay alive forever if screenshots are still being captured
762
+
763
+ Reality:
764
+
765
+ - the watch session shuts itself down after 1 hour with no recent source activity
766
+ - periodic screenshots do not count as source activity
767
+
768
+ Fix:
769
+
770
+ - restart the watch command when you are ready to continue
771
+ - keep editing the watched source if you want the session to remain active
772
+ - read the exit summary: it reports the idle threshold, last source activity time, and recent build results
773
+
774
+ ### Screenshot capture failed in `web screenshot` or `web watch -s`
775
+
776
+ Why it happens:
777
+
778
+ - package dependencies have not been installed yet in the local checkout
779
+ - the headless browser could not start in the current environment
780
+ - the compiled HTML was generated, but the render step failed afterward
781
+
782
+ Fix:
783
+
784
+ - run `npm install` inside the package checkout
785
+ - try `web home.web` first to confirm compilation succeeds without the screenshot step
786
+ - then rerun `web screenshot home.web` or `web watch home.web -s`
787
+ - if the CLI prints a screenshot error, read the full message because it is reported separately from compile errors
788
+
789
+ ### `No .web files found for "..."` or `No WEB source matched "..."`
790
+
791
+ Why it happens:
792
+
793
+ - the path does not exist
794
+ - the directory has no direct `.web` files
795
+ - the glob matched something other than `.web` files
796
+
797
+ Fix:
798
+
799
+ - check your current working directory
800
+ - verify the target path exists
801
+ - verify the file actually ends with `.web`
802
+ - use a more specific glob if needed
803
+
804
+ ## 9. Wrong vs Right Mental Model
805
+
806
+ If something feels confusing, use this mapping:
807
+
808
+ - normal block like `pageMain { ... }`
809
+ - creates HTML structure and can also carry styles
810
+ - path assignment like `pageMain.heroTitle.color = "#223344";`
811
+ - targets a real node path and produces CSS or content depending on the property
812
+ - `styles { ... }`
813
+ - CSS only
814
+ - `::hover`, `::before`, `::media`
815
+ - CSS only
816
+ - `::attrs`
817
+ - HTML attributes only
818
+ - `::head`
819
+ - document head entries only
820
+ - `::script`
821
+ - emitted script tags only
822
+ - `define`
823
+ - declarations only
824
+
825
+ ## 10. Recommended Debug Workflow
826
+
827
+ When a file breaks:
828
+
829
+ 1. Read the `Phase:` line to see whether this is syntax, semantics, HTML generation, or CSS generation.
830
+ 2. Read `Violation:` before changing code. It explains the actual rule.
831
+ 3. Look at `Found:` to see what token or character the compiler was actually reading.
832
+ 4. Use the `Context:` frame, not just the line number. The actual problem is often one line earlier.
833
+ 5. Fix one error at a time and re-run the compiler.
834
+ 6. If the CLI target failed before compilation, confirm the target resolves to a real `.web` file.
835
+
836
+ ## 11. When In Doubt
837
+
838
+ If you are unsure where code belongs, start from the simplest legal structure:
839
+
840
+ ```web
841
+ define {
842
+ @accent = "#94a7ca";
843
+ Main pageMain;
844
+ Heading1 heroTitle;
845
+ }
846
+
847
+ pageMain {
848
+ padding = "2rem";
849
+
850
+ heroTitle {
851
+ textContent = "Hello";
852
+ color = @accent;
853
+ }
854
+ }
855
+ ```
856
+
857
+ Then add:
858
+
859
+ - `::attrs` for attributes
860
+ - `styles` or `::pseudo` for CSS-only variations
861
+ - `::head` for metadata
862
+ - `::script` for emitted browser scripts
863
+ - `raw` only when normal WEB syntax is not enough