@rbxts/scribe 2.5.0 → 2.6.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.
@@ -126,7 +126,7 @@ local function accessorAt(ctx: any, path: { string | number }): any
126
126
  local accessor = ctx.Tree.Accessor
127
127
  for _, segment in path do
128
128
  local ok, child = pcall(function()
129
- return accessor[segment]
129
+ return accessor.Child(segment)
130
130
  end)
131
131
  if not ok or child == nil then
132
132
  fail(`no accessor at "{Util.pathString(path)}"`)
@@ -267,7 +267,7 @@ end
267
267
  --- How many the element at `key` holds, and the leaf accessor that counts it. One reader
268
268
  --- for both element shapes, so no caller branches on `Count` being nil.
269
269
  local function stackCount(ctx: any, leg: Leg, plan: Plan, stored: any): (number, any)
270
- local entryAccessor = accessorAt(ctx, leg.Path)[leg.Key]
270
+ local entryAccessor = accessorAt(ctx, leg.Path).Child(leg.Key)
271
271
  if entryAccessor == nil then
272
272
  fail(`stack leg at "{Util.pathString(leg.Path)}" has no accessor at "{tostring(leg.Key)}"`)
273
273
  end
@@ -276,7 +276,7 @@ local function stackCount(ctx: any, leg: Leg, plan: Plan, stored: any): (number,
276
276
  if type(held) ~= "number" or held ~= held or held % 1 ~= 0 then
277
277
  fail(`stack leg at "{Util.pathString(leg.Path)}" holds no integer count at "{tostring(leg.Key)}"`)
278
278
  end
279
- return held, if countField == nil then entryAccessor else entryAccessor[countField]
279
+ return held, if countField == nil then entryAccessor else entryAccessor.Child(countField)
280
280
  end
281
281
 
282
282
  --- Reject a Stack amount before anything reads a balance against it.
@@ -449,7 +449,7 @@ local function takeKey(ctx: any, leg: Leg, node: any, kind: string): ()
449
449
  end
450
450
  else
451
451
  assertUsableKey(leg.Key, node)
452
- if accessor[leg.Key].Get() == nil then
452
+ if accessor.Child(leg.Key).Get() == nil then
453
453
  fail(`key leg at "{Util.pathString(leg.Path)}" does not hold "{tostring(leg.Key)}"`)
454
454
  end
455
455
  -- Remove, never Set(nil): Set(nil) returns nil on a hit AND on a miss, so it
@@ -457,7 +457,7 @@ local function takeKey(ctx: any, leg: Leg, node: any, kind: string): ()
457
457
  if accessor.Remove(leg.Key) == nil then
458
458
  fail(`key leg at "{Util.pathString(leg.Path)}" Remove reported a miss`)
459
459
  end
460
- if accessor[leg.Key].Get() ~= nil then
460
+ if accessor.Child(leg.Key).Get() ~= nil then
461
461
  fail(`key leg at "{Util.pathString(leg.Path)}" key survived Remove`)
462
462
  end
463
463
  end
@@ -510,12 +510,12 @@ local function giveKey(ctx: any, leg: Leg, node: any, kind: string): ()
510
510
  assertUsableKey(leg.Key, node)
511
511
  -- I2. Vacancy is what makes both proofs bite: an occupied key either no-ops
512
512
  -- (scalar element) or silently clobbers (record element).
513
- if accessor[leg.Key].Get() ~= nil then
513
+ if accessor.Child(leg.Key).Get() ~= nil then
514
514
  fail(`key leg at "{Util.pathString(leg.Path)}" destination key "{tostring(leg.Key)}" is occupied`)
515
515
  end
516
516
  -- The whole element at the key, never a leaf field: a leaf write materialises
517
517
  -- the element from its defaults first and then no-ops if it equals the default.
518
- local returned = accessor[leg.Key].Set(leg.Value)
518
+ local returned = accessor.Child(leg.Key).Set(leg.Value)
519
519
  -- Non-nil only. Set returns the UNPACKED form, a fresh table of real datatypes
520
520
  -- for a packed element, so comparing it to a packed payload fails on exactly
521
521
  -- the elements the packed payload exists to carry.
@@ -5,8 +5,7 @@
5
5
  -- Failed transient service-side; a retry may work
6
6
  -- Unresolved timed out and the write may have landed; never retry blindly
7
7
  -- Rejected permanently invalid; every retry fails identically
8
- -- Only the numeric prefix of the error string is read; the prose is not a contract.
9
- -- An unrecognised code classifies as Failed, with the code in the log context.
8
+ -- Classify by numeric code or throttle name; unknown codes default to Failed.
10
9
 
11
10
  local Health = require(script.Parent.Health)
12
11
  local Log = require(script.Parent.Log)
@@ -46,6 +45,12 @@ local function byFamily(code: number): Class
46
45
  return "Failed"
47
46
  end
48
47
 
48
+ -- Strip known engine prefixes before reading the leading code or throttle name.
49
+ local function withoutEnginePrefix(message: string): string
50
+ local rest = string.match(message, "^%s*HTTP %d+ %b()%s*(.*)$") or message
51
+ return string.match(rest, "^%s*DataStoreService:%s*(.*)$") or rest
52
+ end
53
+
49
54
  --- The numeric code a DataStore error message carries, or nil if it carries none.
50
55
  --- Anchored on purpose: a loose search for digits-then-colon would eventually match a
51
56
  --- number inside a key name and report a confident wrong class. nil classifies as
@@ -54,14 +59,43 @@ function Failure.CodeOf(message: any): number?
54
59
  if type(message) ~= "string" then
55
60
  return nil
56
61
  end
57
- return tonumber(string.match(message, "^%s*(%d+):"))
62
+ return tonumber(string.match(withoutEnginePrefix(message), "^%s*(%d+):"))
63
+ end
64
+
65
+ -- Named throttles have no numeric code. Anchor to avoid matching key names.
66
+ function Failure.IsNamedThrottle(message: any): boolean
67
+ if type(message) ~= "string" then
68
+ return false
69
+ end
70
+ return string.match(withoutEnginePrefix(message), "^%s*%a+Throttled?:") ~= nil
71
+ end
72
+
73
+ -- Lowercase markers for backend throttles wrapped in a 502.
74
+ local WRAPPED_THROTTLE_MARKERS = { "http 429", "too many requests", "request rate exceeds" }
75
+
76
+ -- Treat wrapped throttles as throttling for health and kick messages only.
77
+ -- Classify keeps 502 as Failed: gift refunds require proof that nothing was written.
78
+ function Failure.IsThrottleLike(message: any): boolean
79
+ if Failure.Classify(message) == "Throttled" then
80
+ return true
81
+ end
82
+ if Failure.CodeOf(message) ~= 502 then
83
+ return false
84
+ end
85
+ local text = string.lower(message)
86
+ for _, marker in WRAPPED_THROTTLE_MARKERS do
87
+ if string.find(text, marker, 1, true) then
88
+ return true
89
+ end
90
+ end
91
+ return false
58
92
  end
59
93
 
60
94
  --- Classify a DataStore error message.
61
95
  function Failure.Classify(message: any): Class
62
96
  local code = Failure.CodeOf(message)
63
97
  if code == nil then
64
- return "Failed"
98
+ return if Failure.IsNamedThrottle(message) then "Throttled" else "Failed"
65
99
  end
66
100
  return EXPLICIT[code] or byFamily(code)
67
101
  end
@@ -106,7 +140,9 @@ function Failure.Report(report: Report): (Class, boolean)
106
140
  local classified = report.Error ~= nil or report.Class ~= nil
107
141
  local class: Class = report.Class or Failure.Classify(report.Error)
108
142
 
109
- local counted, folded = Health.ReportFailure(report.Subsystem, report.Key, class)
143
+ -- Fold wrapped throttles in health without changing the reported class.
144
+ local healthClass = if class ~= "Throttled" and Failure.IsThrottleLike(report.Error) then "Throttled" else class
145
+ local counted, folded = Health.ReportFailure(report.Subsystem, report.Key, healthClass)
110
146
 
111
147
  local metric = report.Metric
112
148
  if metric ~= nil then