@@ -677,10 +677,14 @@ def _open_impl(cls, self, fd, uri=None, mode='r',
677677 ignore_missing_extensions = ignore_missing_extensions ,
678678 _extension_metadata = self ._extension_metadata )
679679 except ValueError :
680- pass
681- raise ValueError (
682- "Input object does not appear to be ASDF file or FITS with " +
683- "ASDF extension" )
680+ raise ValueError (
681+ "Input object does not appear to be an ASDF file or a FITS with " +
682+ "ASDF extension" ) from None
683+ except ImportError :
684+ raise ValueError (
685+ "Input object does not appear to be an ASDF file. Cannot check " +
686+ "if it is a FITS with ASDF extension because 'astropy' is not " +
687+ "installed" ) from None
684688 return cls ._open_asdf (self , fd , uri = uri , mode = mode ,
685689 validate_checksums = validate_checksums ,
686690 do_not_fill_defaults = do_not_fill_defaults ,
@@ -827,6 +831,7 @@ def _pre_write(self, fd, all_array_storage, all_array_compression,
827831 self ._blocks .finalize (self )
828832
829833 self ._tree ['asdf_library' ] = get_asdf_library_info ()
834+ self ._update_extension_history ()
830835
831836 def _serial_write (self , fd , pad_blocks , include_block_index ):
832837 self ._write_tree (self ._tree , fd , pad_blocks )
@@ -912,8 +917,6 @@ def update(self, all_array_storage=None, all_array_compression='input',
912917 write out in the latest version supported by asdf.
913918 """
914919
915- self ._update_extension_history ()
916-
917920 fd = self ._fd
918921
919922 if fd is None :
@@ -922,7 +925,9 @@ def update(self, all_array_storage=None, all_array_compression='input',
922925
923926 if not fd .writable ():
924927 raise IOError (
925- "Can not update, since associated file is read-only" )
928+ "Can not update, since associated file is read-only. Make "
929+ "sure that the AsdfFile was opened with mode='rw' and the "
930+ "underlying file handle is writable." )
926931
927932 if version is not None :
928933 self .version = version
@@ -1054,8 +1059,6 @@ def write_to(self, fd, all_array_storage=None, all_array_compression='input',
10541059 write out in the latest version supported by asdf.
10551060 """
10561061
1057- self ._update_extension_history ()
1058-
10591062 original_fd = self ._fd
10601063
10611064 if version is not None :
0 commit comments