diff --git a/libs/gambit/parse-error.scm b/libs/gambit/parse-error.scm
index 5ec089d..08698ce 100644
--- a/libs/gambit/parse-error.scm
+++ b/libs/gambit/parse-error.scm
@@ -39,13 +39,34 @@
 ;;; location of the error in input file.
 ;;; Other parameters are considered as error messages,
 ;;;  they are printed to stderr as is.
+
+
+;; only device ports do carry positions (string ports don't),
+;; return #f for those
+(define (maybe-input-port-byte-position port)
+  (if (port? port)
+      (with-exception-catcher
+       (lambda (e)
+	 (cond ((type-exception? e)
+		#f)
+	       (else
+		(raise e))))
+       (lambda ()
+	 (input-port-byte-position port)))
+      (error "not a port:" port)))
+
+(define (try-cerr-at-position port)
+  (cond ((maybe-input-port-byte-position port)
+	 => (lambda (pos)
+	      (cerr " at position " pos nl)))))
+
 (define parser-error
   (lambda  args
     (if
       (##port? (car args))
       (begin
 	(cerr nl "Error: " (port-name (car args)))
-	(cerr " at position " (input-port-byte-position (car args)) nl)
+	(try-cerr-at-position (car args))
 	; (apply cerr (cdr args)))  
 	(cerr (cdr args)))
       (cerr nl "Error in error handler :-) " nl args))
@@ -56,9 +77,10 @@
   (lambda  args
     (if
       (##port? (car args))
-	(cerr nl "Warning: " (port-name (car args))
-	      " at position " (input-port-byte-position (car args)) nl
-	      (cdr args) nl)
+      (begin
+	(cerr nl "Warning: " (port-name (car args)))
+	(try-cerr-at-position (car args))
+	(cerr (cdr args) nl))
 	#f)
     ))
 
