Skip to content

Commit 8e700dd

Browse files
fix: replace error with Base.error for consistency in error handling
1 parent ba278c7 commit 8e700dd

3 files changed

Lines changed: 29 additions & 33 deletions

File tree

docs/showcase/showcase.ipynb

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
11
{
22
"cells": [
3-
{
4-
"cell_type": "code",
5-
"execution_count": null,
6-
"id": "bff45daf",
7-
"metadata": {},
8-
"outputs": [],
9-
"source": [
10-
"using Conda\n",
11-
"Conda.add_channel(\"conda-forge\")\n",
12-
"Conda.add(\"rise\")"
13-
]
14-
},
153
{
164
"cell_type": "code",
175
"execution_count": null,
@@ -25,8 +13,16 @@
2513
}
2614
],
2715
"metadata": {
16+
"kernelspec": {
17+
"display_name": "Julia 1.11.6",
18+
"language": "julia",
19+
"name": "julia-1.11"
20+
},
2821
"language_info": {
29-
"name": "python"
22+
"file_extension": ".jl",
23+
"mimetype": "application/julia",
24+
"name": "julia",
25+
"version": "1.11.6"
3026
}
3127
},
3228
"nbformat": 4,

src/importexport/cableslibrary.jl

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ Helper function to reconstruct a [`ConductorGroup`](@ref) or [`InsulatorGroup`](
274274
"""
275275
function _reconstruct_partsgroup(layer_data::Dict)
276276
if !haskey(layer_data, "__julia_type__")
277-
error("Layer data missing '__julia_type__' key: $layer_data")
277+
Base.error("Layer data missing '__julia_type__' key: $layer_data")
278278
end
279279
type_str = layer_data["__julia_type__"]
280280
LayerType = _resolve_type(type_str)
@@ -312,7 +312,7 @@ function _reconstruct_partsgroup(layer_data::Dict)
312312

313313
# Check for essential properties common to most first layers
314314
ismissing(radius_in) &&
315-
error("Missing 'radius_in' for first layer type $LayerType in data: $layer_data")
315+
Base.error("Missing 'radius_in' for first layer type $LayerType in data: $layer_data")
316316
ismissing(material_props) && error(
317317
"Missing 'material_props' for first layer type $LayerType in data: $layer_data",
318318
)
@@ -348,7 +348,7 @@ function _reconstruct_partsgroup(layer_data::Dict)
348348
)
349349
elseif LayerType == Tubular
350350
radius_ext = get_as(deserialized_layer_dict, :radius_ext, missing, BASE_FLOAT)
351-
ismissing(radius_ext) && error("Missing 'radius_ext' for Tubular first layer.")
351+
ismissing(radius_ext) && Base.error("Missing 'radius_ext' for Tubular first layer.")
352352
return Tubular(
353353
radius_in, radius_ext, material_props; temperature=temperature)
354354
elseif LayerType == Strip
@@ -373,7 +373,7 @@ function _reconstruct_partsgroup(layer_data::Dict)
373373
elseif LayerType == Insulator
374374
radius_ext = get_as(deserialized_layer_dict, :radius_ext, missing, BASE_FLOAT)
375375
ismissing(radius_ext) &&
376-
error("Missing 'radius_ext' for Insulator first layer.")
376+
Base.error("Missing 'radius_ext' for Insulator first layer.")
377377
return Insulator(
378378
radius_in,
379379
radius_ext,
@@ -382,10 +382,10 @@ function _reconstruct_partsgroup(layer_data::Dict)
382382
)
383383
elseif LayerType == Semicon
384384
radius_ext = get_as(deserialized_layer_dict, :radius_ext, missing, BASE_FLOAT)
385-
ismissing(radius_ext) && error("Missing 'radius_ext' for Semicon first layer.")
385+
ismissing(radius_ext) && Base.error("Missing 'radius_ext' for Semicon first layer.")
386386
return Semicon(radius_in, radius_ext, material_props; temperature=temperature)
387387
else
388-
error("Unsupported layer type for first layer reconstruction: $LayerType")
388+
Base.error("Unsupported layer type for first layer reconstruction: $LayerType")
389389
end
390390
catch e
391391
@error "Construction failed for first layer of type $LayerType with data: $deserialized_layer_dict. Error: $e"
@@ -452,7 +452,7 @@ function _reconstruct_cabledesign(
452452
# 2. Process Components Sequentially
453453
components_data = get(design_data, "components", [])
454454
if isempty(components_data) || !(components_data isa AbstractVector)
455-
error("Missing or invalid 'components' array in design data for $cable_id")
455+
Base.error("Missing or invalid 'components' array in design data for $cable_id")
456456
end
457457

458458
reconstructed_components = CableComponent[] # Store fully built components
@@ -472,7 +472,7 @@ function _reconstruct_cabledesign(
472472
cond_layers_data = get(conductor_group_data, "layers", [])
473473

474474
if isempty(cond_layers_data) || !(cond_layers_data isa AbstractVector)
475-
error("Component '$comp_id' has missing or invalid conductor group layers.")
475+
Base.error("Component '$comp_id' has missing or invalid conductor group layers.")
476476
end
477477

478478
# - Create the FIRST layer object
@@ -500,7 +500,7 @@ function _reconstruct_cabledesign(
500500
# Extract Type and necessary arguments for add!
501501
LayerType = _resolve_type(layer_data["__julia_type__"])
502502
material_props = get_as(layer_data, "material_props", missing, BASE_FLOAT)
503-
material_props isa Material || error("'material_props' must deserialize to Material, got $(typeof(material_props))")
503+
material_props isa Material || Base.error("'material_props' must deserialize to Material, got $(typeof(material_props))")
504504

505505
# Prepare args and kwargs based on LayerType for add!
506506
args = []
@@ -523,17 +523,17 @@ function _reconstruct_cabledesign(
523523
elseif LayerType == Tubular
524524
radius_ext = get_as(layer_data, "radius_ext", missing, BASE_FLOAT)
525525
ismissing(radius_ext) &&
526-
error("Missing 'radius_ext' for Tubular layer $i in $comp_id")
526+
Base.error("Missing 'radius_ext' for Tubular layer $i in $comp_id")
527527
args = [radius_ext, material_props]
528528
elseif LayerType == Strip
529529
radius_ext = get_as(layer_data, "radius_ext", missing, BASE_FLOAT)
530530
width = get_as(layer_data, "width", missing, BASE_FLOAT)
531531
lay_ratio = get_as(layer_data, "lay_ratio", missing, BASE_FLOAT)
532532
any(ismissing, (radius_ext, width, lay_ratio)) &&
533-
error("Missing required field(s) for Strip layer $i in $comp_id")
533+
Base.error("Missing required field(s) for Strip layer $i in $comp_id")
534534
args = [radius_ext, width, lay_ratio, material_props]
535535
else
536-
error("Unsupported layer type '$LayerType' for add!")
536+
Base.error("Unsupported layer type '$LayerType' for add!")
537537
end
538538

539539
# Call add! with Type, args..., and kwargs...
@@ -554,7 +554,7 @@ function _reconstruct_cabledesign(
554554
insu_layers_data = get(insulator_group_data, "layers", [])
555555

556556
if isempty(insu_layers_data) || !(insu_layers_data isa AbstractVector)
557-
error("Component '$comp_id' has missing or invalid insulator group layers.")
557+
Base.error("Component '$comp_id' has missing or invalid insulator group layers.")
558558
end
559559

560560
# - Create the FIRST layer object
@@ -580,7 +580,7 @@ function _reconstruct_cabledesign(
580580

581581
LayerType = _resolve_type(layer_data["__julia_type__"])
582582
material_props = get_as(layer_data, "material_props", missing, BASE_FLOAT)
583-
material_props isa Material || error("'material_props' must deserialize to Material, got $(typeof(material_props))")
583+
material_props isa Material || Base.error("'material_props' must deserialize to Material, got $(typeof(material_props))")
584584

585585

586586
args = []
@@ -593,10 +593,10 @@ function _reconstruct_cabledesign(
593593
if LayerType in [Semicon, Insulator]
594594
radius_ext = get_as(layer_data, "radius_ext", missing, BASE_FLOAT)
595595
ismissing(radius_ext) &&
596-
error("Missing 'radius_ext' for $LayerType layer $i in $comp_id")
596+
Base.error("Missing 'radius_ext' for $LayerType layer $i in $comp_id")
597597
args = [radius_ext, material_props]
598598
else
599-
error("Unsupported layer type '$LayerType' for add!")
599+
Base.error("Unsupported layer type '$LayerType' for add!")
600600
end
601601

602602
# Call add! with Type, args..., and kwargs...
@@ -620,7 +620,7 @@ function _reconstruct_cabledesign(
620620

621621
# 3. Create the final CableDesign object using the first component
622622
if isempty(reconstructed_components)
623-
error("Failed to reconstruct any valid components for cable design '$cable_id'")
623+
Base.error("Failed to reconstruct any valid components for cable design '$cable_id'")
624624
end
625625
# Use the CableDesign constructor which takes the first component
626626
cable_design =

src/utils/macros.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ macro parameterize(container_expr, union_expr)
99
# Core.eval gets the *value* of the symbol passed in (e.g., the actual Union type)
1010
union_type = Core.eval(__module__, union_expr)
1111
catch e
12-
error("Expression `$union_expr` could not be evaluated. Make sure it's a defined const or type.")
12+
Base.error("Expression `$union_expr` could not be evaluated. Make sure it's a defined const or type.")
1313
end
1414

1515
# Sanity check
1616
if !(union_type isa Union)
17-
error("Second argument must be a Union type. Got a `$(typeof(union_type))` instead.")
17+
Base.error("Second argument must be a Union type. Got a `$(typeof(union_type))` instead.")
1818
end
1919

2020
# Base.uniontypes gets the component types, e.g., (Float64, Measurement{Float64})
@@ -94,7 +94,7 @@ macro measurify(def)
9494
if def.head == :(=)
9595
def = MacroTools.longdef(def)
9696
elseif def.head != :function
97-
error("@measurify must wrap a function definition")
97+
Base.error("@measurify must wrap a function definition")
9898
end
9999
dict = MacroTools.splitdef(def)
100100

0 commit comments

Comments
 (0)