metanorma-plugin-lutaml 0.7.31 → 0.7.32

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dda89cf25e4d97114f8285719533a301e4a932b36011212d07dc9c4e386eb8e0
4
- data.tar.gz: b2f0d0296c064be11a5031643bc2ae4d4428b034f475beb6958f24f41d5e3760
3
+ metadata.gz: cd1f666910d8626ed3c60a6543c1d0922a1b988941acb672484757dc42e4e1d2
4
+ data.tar.gz: f40aa319451eaf3444f9bbb06a45aa2f28281fb81d9bc0db40fa5f2699c52d6d
5
5
  SHA512:
6
- metadata.gz: 8c16366f081e6c73776903a6eb930a1b08f0ad7332b6ed240d7318b4a9f2790740cedd20ae68845ffc6205bbb1bc3d629b21c096b7f99534b5b614a32c520d7f
7
- data.tar.gz: 8c7488d45307134a5de8f84adabc88eba63572baa8f5dd19187d823a25a8e46183632e9b47e4e7932833ca291ece2e03db6e118cc533c30f6f3d862c2a049774
6
+ metadata.gz: '096af413077b87f001e1746914fe05f833c83ff698d60383c57e7daf4aa88aae61244d034836ea01eb66bd787940065c4689210d2e9bf7de69b499e6ee96adf5'
7
+ data.tar.gz: 9873bf6b1a5439de6c1aa6480631fc820a0a857e079438fa7ee987cd3fa6a2d069976986d587345bd9e1f4a6466efcae087d06f88647316d3b1afbb46021c0ae
@@ -604,6 +604,22 @@ dolor sit
604
604
  ====
605
605
 
606
606
 
607
+ === Error Handling
608
+
609
+ ==== Invalid JSON or YAML file
610
+
611
+ If the specified file is an invalid JSON or YAML file, the block will raise an
612
+ error when the document is processed. The error will be:
613
+ `Metanorma::Plugin::Lutaml::ParseError`.
614
+
615
+ Detailed error messages will also be provided for troubleshooting.
616
+
617
+ ==== Invalid path of file
618
+
619
+ If the specified file path does not exist, the block will raise an
620
+ error when the document is processed. The error will be:
621
+ `Metanorma::Plugin::Lutaml::FileNotFoundError`.
622
+
607
623
  === Advanced usage
608
624
 
609
625
  ==== General
@@ -93,10 +93,6 @@ module Metanorma
93
93
  include_path: include_path,
94
94
  template_path: template_path,
95
95
  )
96
- rescue StandardError => e
97
- ::Metanorma::Util.log("Failed to parse #{config[:block_name]} \
98
- block: #{e.message}", :error)
99
- []
100
96
  end
101
97
 
102
98
  def resolve_context(document, block_match) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
@@ -2,6 +2,8 @@
2
2
 
3
3
  require "json"
4
4
  require "yaml"
5
+ require_relative "file_not_found_error"
6
+ require_relative "parse_error"
5
7
 
6
8
  module Metanorma
7
9
  module Plugin
@@ -10,21 +12,15 @@ module Metanorma
10
12
  protected
11
13
 
12
14
  # https://ruby-doc.org/stdlib-2.5.1/libdoc/psych/rdoc/Psych.html#method-c-safe_load
13
- def yaml_content_from_file(resolved_file_path) # rubocop:disable Metrics/MethodLength
14
- unless File.exist?(resolved_file_path)
15
- ::Metanorma::Util.log(
16
- "YAML file referenced in [yaml2text] block not found: " \
17
- "#{resolved_file_path}", :error
18
- )
19
- return
20
- end
21
-
15
+ def yaml_content_from_file(resolved_file_path)
22
16
  YAML.safe_load(
23
17
  File.read(resolved_file_path, encoding: "UTF-8"),
24
18
  permitted_classes: [Date, Time, Symbol],
25
19
  permitted_symbols: [],
26
20
  aliases: true,
27
21
  )
22
+ rescue StandardError => e
23
+ raise_parsing_error(e, resolved_file_path, type: :yaml, from: :file)
28
24
  end
29
25
 
30
26
  def yaml_content_from_anchor(document, anchor)
@@ -34,14 +30,34 @@ module Metanorma
34
30
  permitted_symbols: [],
35
31
  aliases: true,
36
32
  )
33
+ rescue StandardError => e
34
+ raise_parsing_error(e, resolved_file_path, type: :yaml, from: :anchor)
37
35
  end
38
36
 
39
37
  def json_content_from_file(resolved_file_path)
40
38
  JSON.parse(File.read(resolved_file_path, encoding: "UTF-8"))
39
+ rescue StandardError => e
40
+ raise_parsing_error(e, resolved_file_path, type: :json, from: :file)
41
41
  end
42
42
 
43
43
  def json_content_from_anchor(document, anchor)
44
44
  JSON.parse(document.attributes["source_blocks"][anchor])
45
+ rescue StandardError => e
46
+ raise_parsing_error(e, resolved_file_path, type: :json, from: :anchor)
47
+ end
48
+
49
+ def raise_parsing_error(error, file_or_anchor, type: :json, from: :file)
50
+ err_msg = "Error parsing #{type} from #{from} " \
51
+ "#{file_or_anchor}: #{error.message}"
52
+ ::Metanorma::Util.log(err_msg, :error)
53
+ raise ::Metanorma::Plugin::Lutaml::ParseError.new err_msg
54
+ end
55
+
56
+ def raise_file_not_found_error(file_path)
57
+ err_msg = "File referenced in [{data|yaml|json}2text] block " \
58
+ "not found: #{file_path}"
59
+ ::Metanorma::Util.log(err_msg, :error)
60
+ raise ::Metanorma::Plugin::Lutaml::FileNotFoundError.new err_msg
45
61
  end
46
62
 
47
63
  def content_from_file(document, file_path)
@@ -51,9 +67,7 @@ module Metanorma
51
67
 
52
68
  def load_content_from_file(resolved_file_path)
53
69
  unless File.exist?(resolved_file_path)
54
- ::Metanorma::Util
55
- .log("Failed to load content from file: #{resolved_file_path}",
56
- :error)
70
+ raise_file_not_found_error(resolved_file_path)
57
71
  end
58
72
 
59
73
  if json_file?(resolved_file_path)
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metanorma
4
+ module Plugin
5
+ module Lutaml
6
+ class FileNotFoundError < StandardError
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metanorma
4
+ module Plugin
5
+ module Lutaml
6
+ class ParseError < StandardError
7
+ end
8
+ end
9
+ end
10
+ end
@@ -1,7 +1,7 @@
1
1
  module Metanorma
2
2
  module Plugin
3
3
  module Lutaml
4
- VERSION = "0.7.31".freeze
4
+ VERSION = "0.7.32".freeze
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-plugin-lutaml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.31
4
+ version: 0.7.32
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-05-23 00:00:00.000000000 Z
11
+ date: 2025-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor
@@ -158,6 +158,7 @@ files:
158
158
  - lib/metanorma/plugin/lutaml/content.rb
159
159
  - lib/metanorma/plugin/lutaml/data2_text_preprocessor.rb
160
160
  - lib/metanorma/plugin/lutaml/express_remarks_decorator.rb
161
+ - lib/metanorma/plugin/lutaml/file_not_found_error.rb
161
162
  - lib/metanorma/plugin/lutaml/json2_text_preprocessor.rb
162
163
  - lib/metanorma/plugin/lutaml/liquid/custom_blocks/key_iterator.rb
163
164
  - lib/metanorma/plugin/lutaml/liquid/custom_filters/html2adoc.rb
@@ -193,6 +194,7 @@ files:
193
194
  - lib/metanorma/plugin/lutaml/lutaml_preprocessor.rb
194
195
  - lib/metanorma/plugin/lutaml/lutaml_table_inline_macro.rb
195
196
  - lib/metanorma/plugin/lutaml/lutaml_uml_datamodel_description_preprocessor.rb
197
+ - lib/metanorma/plugin/lutaml/parse_error.rb
196
198
  - lib/metanorma/plugin/lutaml/source_extractor.rb
197
199
  - lib/metanorma/plugin/lutaml/utils.rb
198
200
  - lib/metanorma/plugin/lutaml/version.rb