errorResource.go (3529B)
1 // Copyright 2021 The Hugo Authors. All rights reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // http://www.apache.org/licenses/LICENSE-2.0 7 // 8 // Unless required by applicable law or agreed to in writing, software 9 // distributed under the License is distributed on an "AS IS" BASIS, 10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package resources 15 16 import ( 17 "image" 18 19 "github.com/gohugoio/hugo/common/hugio" 20 "github.com/gohugoio/hugo/common/maps" 21 "github.com/gohugoio/hugo/media" 22 "github.com/gohugoio/hugo/resources/images" 23 "github.com/gohugoio/hugo/resources/images/exif" 24 "github.com/gohugoio/hugo/resources/resource" 25 ) 26 27 var ( 28 _ error = (*errorResource)(nil) 29 // Imnage covers all current Resource implementations. 30 _ images.ImageResource = (*errorResource)(nil) 31 // The list of user facing and exported interfaces in resource.go 32 // Note that if we're missing some interface here, the user will still 33 // get an error, but not as pretty. 34 _ resource.ContentResource = (*errorResource)(nil) 35 _ resource.ReadSeekCloserResource = (*errorResource)(nil) 36 _ resource.ResourcesLanguageMerger = (*resource.Resources)(nil) 37 // Make sure it also fails when passed to a pipe function. 38 _ ResourceTransformer = (*errorResource)(nil) 39 ) 40 41 // NewErrorResource wraps err in a Resource where all but the Err method will panic. 42 func NewErrorResource(err resource.ResourceError) resource.Resource { 43 return &errorResource{ResourceError: err} 44 } 45 46 type errorResource struct { 47 resource.ResourceError 48 } 49 50 func (e *errorResource) Err() resource.ResourceError { 51 return e.ResourceError 52 } 53 54 func (e *errorResource) ReadSeekCloser() (hugio.ReadSeekCloser, error) { 55 panic(e.ResourceError) 56 } 57 58 func (e *errorResource) Content() (any, error) { 59 panic(e.ResourceError) 60 } 61 62 func (e *errorResource) ResourceType() string { 63 panic(e.ResourceError) 64 } 65 66 func (e *errorResource) MediaType() media.Type { 67 panic(e.ResourceError) 68 } 69 70 func (e *errorResource) Permalink() string { 71 panic(e.ResourceError) 72 } 73 74 func (e *errorResource) RelPermalink() string { 75 panic(e.ResourceError) 76 } 77 78 func (e *errorResource) Name() string { 79 panic(e.ResourceError) 80 } 81 82 func (e *errorResource) Title() string { 83 panic(e.ResourceError) 84 } 85 86 func (e *errorResource) Params() maps.Params { 87 panic(e.ResourceError) 88 } 89 90 func (e *errorResource) Data() any { 91 panic(e.ResourceError) 92 } 93 94 func (e *errorResource) Height() int { 95 panic(e.ResourceError) 96 } 97 98 func (e *errorResource) Width() int { 99 panic(e.ResourceError) 100 } 101 102 func (e *errorResource) Crop(spec string) (images.ImageResource, error) { 103 panic(e.ResourceError) 104 } 105 106 func (e *errorResource) Fill(spec string) (images.ImageResource, error) { 107 panic(e.ResourceError) 108 } 109 110 func (e *errorResource) Fit(spec string) (images.ImageResource, error) { 111 panic(e.ResourceError) 112 } 113 114 func (e *errorResource) Resize(spec string) (images.ImageResource, error) { 115 panic(e.ResourceError) 116 } 117 118 func (e *errorResource) Filter(filters ...any) (images.ImageResource, error) { 119 panic(e.ResourceError) 120 } 121 122 func (e *errorResource) Exif() *exif.ExifInfo { 123 panic(e.ResourceError) 124 } 125 126 func (e *errorResource) DecodeImage() (image.Image, error) { 127 panic(e.ResourceError) 128 } 129 130 func (e *errorResource) Transform(...ResourceTransformation) (ResourceTransformer, error) { 131 panic(e.ResourceError) 132 }