Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[APICORE-980] Propagate gdal error messages instead of completely obfuscating them #6

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions gdal.go
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,25 @@ func Open(filename string, access Access) (Dataset, error) {
return Dataset{dataset}, nil
}

// Open an existing dataset
func OpenWithError(filename string, access Access) (Dataset, error) {
cFilename := C.CString(filename)
defer C.free(unsafe.Pointer(cFilename))

dataset := C.GDALOpen(cFilename, C.GDALAccess(access))
if dataset == nil {
// Look at the last error message:
// for 404, it should return a "HTTP response code: 404" message and code 3 (CE_Failure)
if C.CPLGetLastErrorType() != C.CE_None {
return Dataset{nil}, fmt.Errorf("Error: %s. dataset '%s' open error", C.GoString(C.CPLGetLastErrorMsg()), filename)

}
// Otherwise, revert to the default message:
return Dataset{nil}, fmt.Errorf("Error: dataset '%s' open error", filename)
}
return Dataset{dataset}, nil
}

// Open an existing dataset
func OpenEx(filename string, flags OpenFlag, allowedDrivers []string,
openOptions []string, siblingFiles []string) (Dataset, error) {
Expand Down