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

Created VSIError to report VSI errors. #98

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ install:
- make generate
- make
- cd ../..
- cd swig/python
- make generate
- make
- cd ../..
- sudo rm -f /usr/lib/libgdal.so*
- sudo make install
- sudo ldconfig
Expand Down Expand Up @@ -149,4 +153,3 @@ notifications:
channels:
- "irc.freenode.org#gdal"
use_notice: true

21 changes: 15 additions & 6 deletions autotest/gcore/basic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,40 +40,49 @@
# Nothing exciting here. Just trying to open non existing files,
# or empty names, or files that are not valid datasets...

def matches_non_existing_error_msg(msg):
m1 = "does not exist in the file system,\nand is not recognized as a supported dataset name.\n" in msg
m2 = msg == 'No such file or directory'
return m1 or m2

def basic_test_1():
gdal.PushErrorHandler( 'CPLQuietErrorHandler' )
ds = gdal.Open('non_existing_ds', gdal.GA_ReadOnly)
gdal.PopErrorHandler()
if ds is None and gdal.GetLastErrorMsg() == '`non_existing_ds\' does not exist in the file system,\nand is not recognized as a supported dataset name.\n':
if ds is None and matches_non_existing_error_msg(gdal.GetLastErrorMsg()):
return 'success'
else:
gdaltest.post_reason('did not get expected error message, got %s' % gdal.GetLastErrorMsg())
return 'fail'

def basic_test_2():
gdal.PushErrorHandler( 'CPLQuietErrorHandler' )
ds = gdal.Open('non_existing_ds', gdal.GA_Update)
gdal.PopErrorHandler()
if ds is None and gdal.GetLastErrorMsg() == '`non_existing_ds\' does not exist in the file system,\nand is not recognized as a supported dataset name.\n':
if ds is None and matches_non_existing_error_msg(gdal.GetLastErrorMsg()):
return 'success'
else:
gdaltest.post_reason('did not get expected error message, got %s' % gdal.GetLastErrorMsg())
return 'fail'

def basic_test_3():
gdal.PushErrorHandler( 'CPLQuietErrorHandler' )
ds = gdal.Open('', gdal.GA_ReadOnly)
gdal.PopErrorHandler()
if ds is None and gdal.GetLastErrorMsg() == '`\' does not exist in the file system,\nand is not recognized as a supported dataset name.\n':
if ds is None and matches_non_existing_error_msg(gdal.GetLastErrorMsg()):
return 'success'
else:
gdaltest.post_reason('did not get expected error message, got %s' % gdal.GetLastErrorMsg())
return 'fail'

def basic_test_4():
gdal.PushErrorHandler( 'CPLQuietErrorHandler' )
ds = gdal.Open('', gdal.GA_Update)
gdal.PopErrorHandler()
if ds is None and gdal.GetLastErrorMsg() == '`\' does not exist in the file system,\nand is not recognized as a supported dataset name.\n':
if ds is None and matches_non_existing_error_msg(gdal.GetLastErrorMsg()):
return 'success'
else:
gdaltest.post_reason('did not get expected error message, got %s' % gdal.GetLastErrorMsg())
return 'fail'

def basic_test_5():
Expand Down Expand Up @@ -106,8 +115,8 @@ def basic_test_7_internal():
except:
# Special case: we should still be able to get the error message
# until we call a new GDAL function
if gdal.GetLastErrorMsg() != '`non_existing_ds\' does not exist in the file system,\nand is not recognized as a supported dataset name.\n':
gdaltest.post_reason('did not get expected error message')
if not matches_non_existing_error_msg(gdal.GetLastErrorMsg()):
gdaltest.post_reason('did not get expected error message, got %s' % gdal.GetLastErrorMsg())
return 'fail'

if gdal.GetLastErrorType() == 0:
Expand Down
94 changes: 51 additions & 43 deletions autotest/gcore/vsis3.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
import gdaltest
import webserver

def open_for_read(uri):
"""
Opens a test file for reading.
"""
return gdal.VSIFOpenExL(uri, 'rb', 1)

###############################################################################
def vsis3_init():

Expand All @@ -59,55 +65,57 @@ def vsis3_1():
if drv is None:
return 'skip'

# RETODO: Bind to swig, change test

# Missing AWS_SECRET_ACCESS_KEY
gdal.ErrorReset()
with gdaltest.error_handler():
f = gdal.VSIFOpenL('/vsis3/foo/bar', 'rb')
if f is not None or gdal.GetLastErrorMsg().find('AWS_SECRET_ACCESS_KEY') < 0:
f = open_for_read('/vsis3/foo/bar')
if f is not None or gdal.VSIGetLastErrorMsg().find('AWS_SECRET_ACCESS_KEY') < 0:
gdaltest.post_reason('fail')
print(gdal.GetLastErrorMsg())
print(gdal.VSIGetLastErrorMsg())
return 'fail'

gdal.ErrorReset()
with gdaltest.error_handler():
f = gdal.VSIFOpenL('/vsis3_streaming/foo/bar', 'rb')
if f is not None or gdal.GetLastErrorMsg().find('AWS_SECRET_ACCESS_KEY') < 0:
f = open_for_read('/vsis3_streaming/foo/bar')
if f is not None or gdal.VSIGetLastErrorMsg().find('AWS_SECRET_ACCESS_KEY') < 0:
gdaltest.post_reason('fail')
print(gdal.GetLastErrorMsg())
print(gdal.VSIGetLastErrorMsg())
return 'fail'

gdal.SetConfigOption('AWS_SECRET_ACCESS_KEY', 'AWS_SECRET_ACCESS_KEY')

# Missing AWS_ACCESS_KEY_ID
gdal.ErrorReset()
with gdaltest.error_handler():
f = gdal.VSIFOpenL('/vsis3/foo/bar', 'rb')
if f is not None or gdal.GetLastErrorMsg().find('AWS_ACCESS_KEY_ID') < 0:
f = open_for_read('/vsis3/foo/bar')
if f is not None or gdal.VSIGetLastErrorMsg().find('AWS_ACCESS_KEY_ID') < 0:
gdaltest.post_reason('fail')
print(gdal.GetLastErrorMsg())
print(gdal.VSIGetLastErrorMsg())
return 'fail'

gdal.SetConfigOption('AWS_ACCESS_KEY_ID', 'AWS_ACCESS_KEY_ID')

# ERROR 1: The AWS Access Key Id you provided does not exist in our records.
gdal.ErrorReset()
with gdaltest.error_handler():
f = gdal.VSIFOpenL('/vsis3/foo/bar.baz', 'rb')
if f is not None or gdal.GetLastErrorMsg() == '':
f = open_for_read('/vsis3/foo/bar.baz')
if f is not None or gdal.VSIGetLastErrorMsg() == '':
if f is not None:
gdal.VSIFCloseL(f)
if gdal.GetConfigOption('APPVEYOR') is not None:
return 'success'
gdaltest.post_reason('fail')
print(gdal.GetLastErrorMsg())
print(gdal.VSIGetLastErrorMsg())
return 'fail'

gdal.ErrorReset()
with gdaltest.error_handler():
f = gdal.VSIFOpenL('/vsis3_streaming/foo/bar.baz', 'rb')
if f is not None or gdal.GetLastErrorMsg() == '':
f = open_for_read('/vsis3_streaming/foo/bar.baz')
if f is not None or gdal.VSIGetLastErrorMsg() == '':
gdaltest.post_reason('fail')
print(gdal.GetLastErrorMsg())
print(gdal.VSIGetLastErrorMsg())
return 'fail'

return 'success'
Expand Down Expand Up @@ -147,7 +155,7 @@ def vsis3_2():
gdal.SetConfigOption('AWS_VIRTUAL_HOSTING', 'NO')
gdal.SetConfigOption('AWS_S3_ENDPOINT', '127.0.0.1:%d' % gdaltest.webserver_port)

f = gdal.VSIFOpenL('/vsis3/s3_fake_bucket/resource', 'rb')
f = open_for_read('/vsis3/s3_fake_bucket/resource')
if f is None:
gdaltest.post_reason('fail')
return 'fail'
Expand All @@ -159,7 +167,7 @@ def vsis3_2():
print(data)
return 'fail'

f = gdal.VSIFOpenL('/vsis3_streaming/s3_fake_bucket/resource', 'rb')
f = open_for_read('/vsis3_streaming/s3_fake_bucket/resource')
if f is None:
gdaltest.post_reason('fail')
return 'fail'
Expand All @@ -173,7 +181,7 @@ def vsis3_2():

# Test with temporary credentials
gdal.SetConfigOption('AWS_SESSION_TOKEN', 'AWS_SESSION_TOKEN')
f = gdal.VSIFOpenL('/vsis3/s3_fake_bucket_with_session_token/resource', 'rb')
f = open_for_read('/vsis3/s3_fake_bucket_with_session_token/resource')
if f is None:
gdaltest.post_reason('fail')
return 'fail'
Expand Down Expand Up @@ -203,7 +211,7 @@ def vsis3_2():
return 'fail'

# Test region and endpoint 'redirects'
f = gdal.VSIFOpenL('/vsis3/s3_fake_bucket/redirect', 'rb')
f = open_for_read('/vsis3/s3_fake_bucket/redirect')
if f is None:
gdaltest.post_reason('fail')
return 'fail'
Expand All @@ -216,7 +224,7 @@ def vsis3_2():
return 'fail'

# Test region and endpoint 'redirects'
f = gdal.VSIFOpenL('/vsis3_streaming/s3_fake_bucket/redirect', 'rb')
f = open_for_read('/vsis3_streaming/s3_fake_bucket/redirect')
if f is None:
gdaltest.post_reason('fail')
return 'fail'
Expand All @@ -230,50 +238,50 @@ def vsis3_2():

gdal.ErrorReset()
with gdaltest.error_handler():
f = gdal.VSIFOpenL('/vsis3_streaming/s3_fake_bucket/non_xml_error', 'rb')
if f is not None or gdal.GetLastErrorMsg().find('bla') < 0:
f = open_for_read('/vsis3_streaming/s3_fake_bucket/non_xml_error')
if f is not None or gdal.VSIGetLastErrorMsg().find('bla') < 0:
gdaltest.post_reason('fail')
print(gdal.GetLastErrorMsg())
print(gdal.VSIGetLastErrorMsg())
return 'fail'

gdal.ErrorReset()
with gdaltest.error_handler():
f = gdal.VSIFOpenL('/vsis3_streaming/s3_fake_bucket/invalid_xml_error', 'rb')
if f is not None or gdal.GetLastErrorMsg().find('<oops>') < 0:
f = open_for_read('/vsis3_streaming/s3_fake_bucket/invalid_xml_error')
if f is not None or gdal.VSIGetLastErrorMsg().find('<oops>') < 0:
gdaltest.post_reason('fail')
print(gdal.GetLastErrorMsg())
print(gdal.VSIGetLastErrorMsg())
return 'fail'

gdal.ErrorReset()
with gdaltest.error_handler():
f = gdal.VSIFOpenL('/vsis3_streaming/s3_fake_bucket/no_code_in_error', 'rb')
if f is not None or gdal.GetLastErrorMsg().find('<Error/>') < 0:
f = open_for_read('/vsis3_streaming/s3_fake_bucket/no_code_in_error')
if f is not None or gdal.VSIGetLastErrorMsg().find('<Error/>') < 0:
gdaltest.post_reason('fail')
print(gdal.GetLastErrorMsg())
print(gdal.VSIGetLastErrorMsg())
return 'fail'

gdal.ErrorReset()
with gdaltest.error_handler():
f = gdal.VSIFOpenL('/vsis3_streaming/s3_fake_bucket/no_region_in_AuthorizationHeaderMalformed_error', 'rb')
if f is not None or gdal.GetLastErrorMsg().find('<Error>') < 0:
f = open_for_read('/vsis3_streaming/s3_fake_bucket/no_region_in_AuthorizationHeaderMalformed_error')
if f is not None or gdal.VSIGetLastErrorMsg().find('<Error>') < 0:
gdaltest.post_reason('fail')
print(gdal.GetLastErrorMsg())
print(gdal.VSIGetLastErrorMsg())
return 'fail'

gdal.ErrorReset()
with gdaltest.error_handler():
f = gdal.VSIFOpenL('/vsis3_streaming/s3_fake_bucket/no_endpoint_in_PermanentRedirect_error', 'rb')
if f is not None or gdal.GetLastErrorMsg().find('<Error>') < 0:
f = open_for_read('/vsis3_streaming/s3_fake_bucket/no_endpoint_in_PermanentRedirect_error')
if f is not None or gdal.VSIGetLastErrorMsg().find('<Error>') < 0:
gdaltest.post_reason('fail')
print(gdal.GetLastErrorMsg())
print(gdal.VSIGetLastErrorMsg())
return 'fail'

gdal.ErrorReset()
with gdaltest.error_handler():
f = gdal.VSIFOpenL('/vsis3_streaming/s3_fake_bucket/no_message_in_error', 'rb')
if f is not None or gdal.GetLastErrorMsg().find('<Error>') < 0:
f = open_for_read('/vsis3_streaming/s3_fake_bucket/no_message_in_error')
if f is not None or gdal.VSIGetLastErrorMsg().find('<Error>') < 0:
gdaltest.post_reason('fail')
print(gdal.GetLastErrorMsg())
print(gdal.VSIGetLastErrorMsg())
return 'fail'

return 'success'
Expand All @@ -285,7 +293,7 @@ def vsis3_3():

if gdaltest.webserver_port == 0:
return 'skip'
f = gdal.VSIFOpenL('/vsis3/s3_fake_bucket2/a_dir/resource3.bin', 'rb')
f = open_for_read('/vsis3/s3_fake_bucket2/a_dir/resource3.bin')
if f is None:
gdaltest.post_reason('fail')
return 'fail'
Expand Down Expand Up @@ -562,7 +570,7 @@ def vsis3_extra_1():
print('Missing S3_RESOURCE for running gdaltest_list_extra')
return 'skip'

f = gdal.VSIFOpenL('/vsis3/' + gdal.GetConfigOption('S3_RESOURCE'), 'rb')
f = open_for_read('/vsis3/' + gdal.GetConfigOption('S3_RESOURCE'))
if f is None:
gdaltest.post_reason('fail')
return 'fail'
Expand All @@ -575,7 +583,7 @@ def vsis3_extra_1():
return 'fail'

# Same with /vsis3_streaming/
f = gdal.VSIFOpenL('/vsis3_streaming/' + gdal.GetConfigOption('S3_RESOURCE'), 'rb')
f = open_for_read('/vsis3_streaming/' + gdal.GetConfigOption('S3_RESOURCE'))
if f is None:
gdaltest.post_reason('fail')
return 'fail'
Expand All @@ -589,7 +597,7 @@ def vsis3_extra_1():

# Invalid bucket : "The specified bucket does not exist"
gdal.ErrorReset()
f = gdal.VSIFOpenL('/vsis3/not_existing_bucket/foo', 'rb')
f = open_for_read('/vsis3/not_existing_bucket/foo')
with gdaltest.error_handler():
gdal.VSIFReadL(1, 1, f)
gdal.VSIFCloseL(f)
Expand All @@ -600,7 +608,7 @@ def vsis3_extra_1():

# Invalid resource
gdal.ErrorReset()
f = gdal.VSIFOpenL('/vsis3_streaming/' + gdal.GetConfigOption('S3_RESOURCE') + '/invalid_resource.baz', 'rb')
f = open_for_read('/vsis3_streaming/' + gdal.GetConfigOption('S3_RESOURCE') + '/invalid_resource.baz')
if f is not None:
gdaltest.post_reason('fail')
print(gdal.GetLastErrorMsg())
Expand Down
8 changes: 4 additions & 4 deletions autotest/utilities/test_gdal_translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def test_gdal_translate_13():
if ds is None:
return 'fail'

md = ds.GetMetadata()
md = ds.GetMetadata()
if 'TIFFTAG_DOCUMENTNAME' not in md:
gdaltest.post_reason('Did not get TIFFTAG_DOCUMENTNAME')
return 'fail'
Expand All @@ -383,7 +383,7 @@ def test_gdal_translate_14():
if ds is None:
return 'fail'

md = ds.GetMetadata('IMAGE_STRUCTURE')
md = ds.GetMetadata('IMAGE_STRUCTURE')
if 'COMPRESSION' not in md or md['COMPRESSION'] != 'LZW':
gdaltest.post_reason('Did not get COMPRESSION')
return 'fail'
Expand Down Expand Up @@ -517,7 +517,7 @@ def test_gdal_translate_19():
return 'skip'

ds = gdal.GetDriverByName('GTiff').Create('tmp/test_gdal_translate_19_src.tif',1,1,2)
ct = gdal.ColorTable()
ct = gdal.ColorTable()
ct.SetColorEntry( 127, (1,2,3,255) )
ds.GetRasterBand( 1 ).SetRasterColorTable( ct )
ds.GetRasterBand( 1 ).Fill(127)
Expand Down Expand Up @@ -977,7 +977,7 @@ def test_gdal_translate_35():
return 'fail'

(out, err) = gdaltest.runexternal_out_and_err(test_cli_utilities.get_gdal_translate_path() + ' /non_existing_path/non_existing.tif /vsimem/out.tif')
if err.find('does not exist in the file system') < 0:
if err.find('No such file or directory') < 0:
gdaltest.post_reason('fail')
print(err)
return 'fail'
Expand Down
6 changes: 4 additions & 2 deletions gdal/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.hostname = "gdal-vagrant"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
config.vm.host_name = "gdal-vagrant"

config.vm.network :forwarded_port, guest: 80, host: 8080

config.vm.synced_folder "../autotest/", "/home/vagrant/autotest/"

config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", vm_ram]
vb.customize ["modifyvm", :id, "--cpus", vm_cpu]
vb.customize ["modifyvm", :id, "--ioapic", "on"]
vb.name = "gdal-vagrant"
end
end

ppaRepos = [
"ppa:ubuntugis/ubuntugis-unstable", "ppa:marlam/gta"
Expand Down
3 changes: 2 additions & 1 deletion gdal/apps/gdalinfo_bin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@ int main( int argc, char ** argv )
while (__AFL_LOOP(1000)) {
iIter ++;
#endif

GDALDatasetH hDataset
= GDALOpenEx( psOptionsForBinary->pszFilename, GDAL_OF_READONLY | GDAL_OF_RASTER, NULL,
= GDALOpenEx( psOptionsForBinary->pszFilename, GDAL_OF_READONLY | GDAL_OF_RASTER | GDAL_OF_VERBOSE_ERROR, NULL,
(const char* const* )psOptionsForBinary->papszOpenOptions, NULL );

if( hDataset == NULL )
Expand Down
Loading