mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-11 12:36:15 +00:00
chore: enable forcetypeassert linter, fix issues (#38804)
Enable [`forcetypeassert`](https://github.com/gostaticanalysis/forcetypeassert) linter to prevent unchecked type assertions. ~650 issues fixed, most fixes were clean, some use `setting.PanicInDevOrTesting`. The only behaviour changes are where code would previously send a 500 error or panic, a 4xx error is now emitted. Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -239,6 +239,15 @@ func GetPackageDescriptorWithCache(ctx context.Context, pv *PackageVersion, c *c
|
||||
}, nil
|
||||
}
|
||||
|
||||
// DescriptorMetadata returns the descriptor's metadata, which getPackageDescriptor has created from the package type
|
||||
func DescriptorMetadata[T interface{ *E }, E any](pd *PackageDescriptor) T {
|
||||
metadata, ok := pd.Metadata.(T)
|
||||
if !ok {
|
||||
panic(fmt.Errorf("package %s of type %s has metadata type %T instead of %T", pd.Package.Name, pd.Package.Type, pd.Metadata, metadata))
|
||||
}
|
||||
return metadata
|
||||
}
|
||||
|
||||
// GetPackageFileDescriptor gets a package file descriptor for a package file
|
||||
func GetPackageFileDescriptor(ctx context.Context, pf *PackageFile) (*PackageFileDescriptor, error) {
|
||||
return getPackageFileDescriptor(ctx, pf, cache.NewEphemeralCache())
|
||||
|
||||
Reference in New Issue
Block a user