#156 PosixSerial.open raises OSError rather than SerialException when port open fails

v2.7
closed-accepted
None
5
2014-09-19
2013-11-26
No

With PySerial 2.7 installed on my Mac OS X computer, when I execute the following Python script:

from serial import Serial
Serial('/dev/nonexistent')

the PySerial PosixSerial.open method raises an OSError. However, looking at this portion of the PosixSerial.open method:

try:
    self.fd = os.open(self.portstr, os.O_RDWR|os.O_NOCTTY|os.O_NONBLOCK)
except IOError, msg:
    self.fd = None
    raise SerialException(msg.errno, "could not open port %s: %s" % (self._port, msg))

it appears that the intent is to raise a SerialException rather than an OSError when the call to os.open fails. This could be fixed, of course, by catching OSError exceptions instead of or in addition to IOError exceptions and responding to them in the same way.

Related

Bugs: #156

Discussion

  • Chris Liechti

    Chris Liechti - 2014-08-04

    Yes that was the intention.
    Thanks, committed.

     
  • Chris Liechti

    Chris Liechti - 2014-08-04
    • status: open --> closed-accepted
    • assigned_to: Chris Liechti
     
    • Harold Mills

      Harold Mills - 2014-08-04

      Great. Thank you for pySerial!

      On Mon, Aug 4, 2014 at 6:36 AM, Chris Liechti cliechti@users.sf.net wrote:

      • status: open --> closed-accepted
      • assigned_to: Chris Liechti
      • Comment:

      Yes that was the intention.
      Thanks, committed.


      Status: closed-accepted
      Group: v2.7

      Created: Tue Nov 26, 2013 05:13 PM UTC by Harold Mills
      Last Updated: Wed Jun 18, 2014 10:43 AM UTC
      Owner: Chris Liechti

      With PySerial 2.7 installed on my Mac OS X computer, when I execute the
      following Python script:

      from serial import SerialSerial('/dev/nonexistent')

      the PySerial PosixSerial.open method raises an OSError. However, looking
      at this portion of the PosixSerial.open method:

      try:
      self.fd = os.open(self.portstr, os.O_RDWR|os.O_NOCTTY|os.O_NONBLOCK)except IOError, msg:
      self.fd = None
      raise SerialException(msg.errno, "could not open port %s: %s" % (self._port, msg))

      it appears that the intent is to raise a SerialException rather than an
      OSError when the call to os.open fails. This could be fixed, of course, by
      catching OSError exceptions instead of or in addition to IOError exceptions
      and responding to them in the same way.


      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/pyserial/bugs/156/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/

       

      Related

      Bugs: #156


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks