A library for handling DID identifiers used in Bluesky AT Protocol

merged all FormatErrors into one FormatError

+30 -35
+2 -3
lib/didkit/at_handles.rb
··· 1 + require_relative 'errors' 2 + 1 3 module DIDKit 2 4 module AtHandles 3 - class FormatError < StandardError 4 - end 5 - 6 5 def parse_also_known_as(aka) 7 6 raise FormatError, "Invalid alsoKnownAs: #{aka.inspect}" unless aka.is_a?(Array) 8 7 raise FormatError, "Invalid alsoKnownAs: #{aka.inspect}" unless aka.all? { |x| x.is_a?(String) }
+1 -3
lib/didkit/document.rb
··· 1 1 require_relative 'at_handles' 2 + require_relative 'errors' 2 3 require_relative 'resolver' 3 4 require_relative 'service_record' 4 5 require_relative 'services' 5 6 6 7 module DIDKit 7 8 class Document 8 - class FormatError < StandardError 9 - end 10 - 11 9 include AtHandles 12 10 include Services 13 11
+3
lib/didkit/errors.rb
··· 18 18 response.body 19 19 end 20 20 end 21 + 22 + class FormatError < StandardError 23 + end 21 24 end
+1 -3
lib/didkit/plc_operation.rb
··· 1 1 require 'time' 2 2 3 3 require_relative 'at_handles' 4 + require_relative 'errors' 4 5 require_relative 'service_record' 5 6 require_relative 'services' 6 7 7 8 module DIDKit 8 9 class PLCOperation 9 - class FormatError < StandardError 10 - end 11 - 12 10 include AtHandles 13 11 include Services 14 12
-3
lib/didkit/service_record.rb
··· 3 3 4 4 module DIDKit 5 5 class ServiceRecord 6 - class FormatError < StandardError 7 - end 8 - 9 6 attr_reader :key, :type, :endpoint 10 7 11 8 def initialize(key, type, endpoint)
+7 -7
spec/document_spec.rb
··· 41 41 it 'should raise a format error' do 42 42 expect { 43 43 subject.new(did, json) 44 - }.to raise_error(DIDKit::Document::FormatError) 44 + }.to raise_error(DIDKit::FormatError) 45 45 end 46 46 end 47 47 ··· 51 51 it 'should raise a format error' do 52 52 expect { 53 53 subject.new(did, json) 54 - }.to raise_error(DIDKit::Document::FormatError) 54 + }.to raise_error(DIDKit::FormatError) 55 55 end 56 56 end 57 57 ··· 61 61 it 'should raise a format error' do 62 62 expect { 63 63 subject.new(did, json) 64 - }.to raise_error(DIDKit::Document::FormatError) 64 + }.to raise_error(DIDKit::FormatError) 65 65 end 66 66 end 67 67 ··· 71 71 it 'should raise an AtHandles format error' do 72 72 expect { 73 73 subject.new(did, json) 74 - }.to raise_error(DIDKit::AtHandles::FormatError) 74 + }.to raise_error(DIDKit::FormatError) 75 75 end 76 76 end 77 77 ··· 81 81 it 'should raise an AtHandles format error' do 82 82 expect { 83 83 subject.new(did, json) 84 - }.to raise_error(DIDKit::AtHandles::FormatError) 84 + }.to raise_error(DIDKit::FormatError) 85 85 end 86 86 end 87 87 ··· 106 106 it 'should raise a format error' do 107 107 expect { 108 108 subject.new(did, json) 109 - }.to raise_error(DIDKit::Document::FormatError) 109 + }.to raise_error(DIDKit::FormatError) 110 110 end 111 111 end 112 112 ··· 116 116 it 'should raise a format error' do 117 117 expect { 118 118 subject.new(did, json) 119 - }.to raise_error(DIDKit::Document::FormatError) 119 + }.to raise_error(DIDKit::FormatError) 120 120 end 121 121 end 122 122
+16 -16
spec/plc_operation_spec.rb
··· 27 27 let(:json) { [base_json] } 28 28 29 29 it 'should raise a format error' do 30 - expect { subject.new(json) }.to raise_error(DIDKit::PLCOperation::FormatError) 30 + expect { subject.new(json) }.to raise_error(DIDKit::FormatError) 31 31 end 32 32 end 33 33 ··· 35 35 let(:json) { base_json.tap { |h| h.delete('did') }} 36 36 37 37 it 'should raise a format error' do 38 - expect { subject.new(json) }.to raise_error(DIDKit::PLCOperation::FormatError) 38 + expect { subject.new(json) }.to raise_error(DIDKit::FormatError) 39 39 end 40 40 end 41 41 ··· 43 43 let(:json) { base_json.merge('did' => 123) } 44 44 45 45 it 'should raise a format error' do 46 - expect { subject.new(json) }.to raise_error(DIDKit::PLCOperation::FormatError) 46 + expect { subject.new(json) }.to raise_error(DIDKit::FormatError) 47 47 end 48 48 end 49 49 ··· 51 51 let(:json) { base_json.merge('did' => 'foobar') } 52 52 53 53 it 'should raise a format error' do 54 - expect { subject.new(json) }.to raise_error(DIDKit::PLCOperation::FormatError) 54 + expect { subject.new(json) }.to raise_error(DIDKit::FormatError) 55 55 end 56 56 end 57 57 ··· 59 59 let(:json) { base_json.tap { |h| h.delete('cid') }} 60 60 61 61 it 'should raise a format error' do 62 - expect { subject.new(json) }.to raise_error(DIDKit::PLCOperation::FormatError) 62 + expect { subject.new(json) }.to raise_error(DIDKit::FormatError) 63 63 end 64 64 end 65 65 ··· 67 67 let(:json) { base_json.merge('cid' => 700) } 68 68 69 69 it 'should raise a format error' do 70 - expect { subject.new(json) }.to raise_error(DIDKit::PLCOperation::FormatError) 70 + expect { subject.new(json) }.to raise_error(DIDKit::FormatError) 71 71 end 72 72 end 73 73 ··· 75 75 let(:json) { base_json.tap { |h| h.delete('createdAt') }} 76 76 77 77 it 'should raise a format error' do 78 - expect { subject.new(json) }.to raise_error(DIDKit::PLCOperation::FormatError) 78 + expect { subject.new(json) }.to raise_error(DIDKit::FormatError) 79 79 end 80 80 end 81 81 ··· 83 83 let(:json) { base_json.merge('createdAt' => 123) } 84 84 85 85 it 'should raise a format error' do 86 - expect { subject.new(json) }.to raise_error(DIDKit::PLCOperation::FormatError) 86 + expect { subject.new(json) }.to raise_error(DIDKit::FormatError) 87 87 end 88 88 end 89 89 ··· 91 91 let(:json) { base_json.tap { |h| h.delete('operation') }} 92 92 93 93 it 'should raise a format error' do 94 - expect { subject.new(json) }.to raise_error(DIDKit::PLCOperation::FormatError) 94 + expect { subject.new(json) }.to raise_error(DIDKit::FormatError) 95 95 end 96 96 end 97 97 ··· 99 99 let(:json) { base_json.merge('operation' => 'invalid') } 100 100 101 101 it 'should raise a format error' do 102 - expect { subject.new(json) }.to raise_error(DIDKit::PLCOperation::FormatError) 102 + expect { subject.new(json) }.to raise_error(DIDKit::FormatError) 103 103 end 104 104 end 105 105 ··· 107 107 let(:json) { base_json.tap { |h| h['operation'].delete('type') }} 108 108 109 109 it 'should raise a format error' do 110 - expect { subject.new(json) }.to raise_error(DIDKit::PLCOperation::FormatError) 110 + expect { subject.new(json) }.to raise_error(DIDKit::FormatError) 111 111 end 112 112 end 113 113 ··· 152 152 it 'should raise an AtHandles format error' do 153 153 expect { 154 154 subject.new(json) 155 - }.to raise_error(DIDKit::AtHandles::FormatError) 155 + }.to raise_error(DIDKit::FormatError) 156 156 end 157 157 end 158 158 ··· 162 162 it 'should raise an AtHandles format error' do 163 163 expect { 164 164 subject.new(json) 165 - }.to raise_error(DIDKit::AtHandles::FormatError) 165 + }.to raise_error(DIDKit::FormatError) 166 166 end 167 167 end 168 168 ··· 187 187 let(:json) { base_json.tap { |h| h['operation'].delete('services') }} 188 188 189 189 it 'should raise a format error' do 190 - expect { subject.new(json) }.to raise_error(DIDKit::PLCOperation::FormatError) 190 + expect { subject.new(json) }.to raise_error(DIDKit::FormatError) 191 191 end 192 192 end 193 193 ··· 205 205 } 206 206 207 207 it 'should raise a format error' do 208 - expect { subject.new(json) }.to raise_error(DIDKit::PLCOperation::FormatError) 208 + expect { subject.new(json) }.to raise_error(DIDKit::FormatError) 209 209 end 210 210 end 211 211 ··· 225 225 } 226 226 227 227 it 'should raise a format error' do 228 - expect { subject.new(json) }.to raise_error(DIDKit::PLCOperation::FormatError) 228 + expect { subject.new(json) }.to raise_error(DIDKit::FormatError) 229 229 end 230 230 end 231 231