Skip to content

Commit

Permalink
fix: minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
GetPsyched committed Nov 3, 2024
1 parent 107841a commit c4ea64d
Showing 1 changed file with 8 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import json
from dataclasses import dataclass, field
from pathlib import Path

from .manual_structure import XrefTarget

Expand All @@ -14,10 +13,9 @@ class Redirects:
_raw_redirects: dict[str, list[str]]
_redirects_script: str

_xref_targets: dict[str, XrefTarget] = field(default_factory=dict)
_errors: list[RedirectsError] = field(default_factory=list)

def validate(self, xref_targets):
def validate(self, xref_targets: dict[str, XrefTarget]):
"""
Parse redirects from an static set of identifier-locations pairs
Expand All @@ -30,9 +28,6 @@ def validate(self, xref_targets):
- Flatten redirects into simple key-value pairs for simpler indexing
- Segregate client and server side redirects
"""
self._xref_targets = xref_targets
redirection_targets = {target.path for target in xref_targets.values()}

identifiers_without_redirects = xref_targets.keys() - self._raw_redirects.keys()
orphan_identifiers = self._raw_redirects.keys() - xref_targets.keys()
if orphan_identifiers:
Expand Down Expand Up @@ -107,7 +102,7 @@ def raise_errors(self, error_type: RedirectsError = None):
if len(errors_to_raise) == 1:
raise errors_to_raise[0]
else:
raise RuntimeError("Multiple errors occurred:", "\n\n".join(errors_to_raise))
raise RedirectsError(f"Multiple validation errors occurred:\n{'\n'.join(map(str, errors_to_raise))}")

def get_client_redirects(self, redirection_target: str):
client_redirects = {}
Expand All @@ -132,9 +127,9 @@ def __str__(self):
conflict_list = "\n - ".join(sorted(self.conflicts))
return f"""
**Conflicting Anchors Found**
An identifier must not match the name of an anchor across any historical location.
An identifier must not match the name of an anchor across any historical location of the same output path.
The following paths voilate the above rule:
The following identifiers voilate the above rule:
- {conflict_list}
This can generally happen when:
Expand Down Expand Up @@ -176,7 +171,7 @@ def __str__(self):
**Invalid Current Paths Found**
The head element of an identifier's corresponding historical location must be its current output location.
The following paths voilate the above rule:
The following identifiers voilate the above rule:
- {invalid_list}
This is problematic because:
Expand All @@ -194,7 +189,7 @@ def __str__(self):
**Redirects Missing**
Every identifier present in the source files must have a mapping in the redirects.
The following paths voilate the above rule:
The following identifiers voilate the above rule:
- {missing_list}
This can generally happen when:
Expand All @@ -216,7 +211,7 @@ def __str__(self):
**Orphan Identifiers Found**
Every key of the redirects mapping must correspond to some identifier in the source files.
The following paths voilate the above rule:
The following identifiers voilate the above rule:
- {orphan_list}
This can generally happen when:
Expand All @@ -235,7 +230,7 @@ def __str__(self):
**Transitive Redirects Found**
Transitivity is disallowed to avoid multiple network calls.
The following paths voilate the above rule:
The following identifiers voilate the above rule:
- {transitive_list}
This can generally happen when:
Expand Down

0 comments on commit c4ea64d

Please sign in to comment.